/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.cdweixin.service.impl;

import com.dmgis.entity.DmMapRectangle;
import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByUpdate;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.ny.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.users;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ActualElemQuery;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.dmgis.qxfw.dataservice.cdweixin.service.WXDataService;
import com.dmgis.weblib.MapCommon;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.github.kevinsawicki.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.MsgMediumSmallScale;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.stream.Stream;

@Service("WXDataService")
public class WXDataServiceImpl implements WXDataService {

    String result = "";
    HttpRequestUtil httpUtil = new HttpRequestUtil();

    ProcessRequestController pc = new ProcessRequestController();

    private  final String operatingSystem;

    @Autowired
    public WXDataServiceImpl(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }

    MongoService1 ms = new MongoService1();
    @Resource
    ITransformService iTransformService;

    ///
    /// 通过兰伯特字符串得到高斯字符串，转成经纬度
    ///
    private WaringPoss GetDotSetByString(String strval) {
        double xval = 0;
        double yval = 0;
        String strnPos = "";
        String[] Poss = strval.substring(0, strval.length() - 1).split("\\*");
        WaringPoss wp = new WaringPoss();
        String Cols = "";
        for (int i = 0; i <= Poss.length - 1; i++) {
            String strtemp = Poss[i];
            int aa = strtemp.indexOf("#");
            if (aa >= 0) {
                Cols += strtemp.substring(0, aa) + "*";
                strtemp = strtemp.substring(aa + 1);

            }
            String[] pos = strtemp.split(",");
            int j = 0;
            while (j < pos.length) {
                try {
                    xval = Double.parseDouble(pos[j].split(" ")[0]);
                    yval = Double.parseDouble(pos[j].split(" ")[1]);
                    DmMapPoint dt1 = iTransformService.LambertConvertToLonLat(xval, yval);
                    // strnPos += String.format("%s %s", xval, yval) + ";";
                    strnPos += String.format("%s,%s", String.valueOf(dt1.x), String.valueOf(dt1.y)) + ";";
                } catch (Exception e) {
                }
                j++;
            }

            strnPos = strnPos.substring(0, strnPos.length() - 1) + "*";
        }
        wp.Poss = strnPos;
        String color = Cols.substring(0, Cols.length() - 1);
        String[] colors = color.split("\\*");
        wp.arr = "";
        for (int i = 0; i < colors.length; i++) {
            wp.arr = wp.arr + ColorUtil.transWin32ToHtml(Integer.parseInt(colors[i])) + "*";
        }
        return wp;
    }

    @Override
    public String InitSkMaxTime() {

        // TODO 区域自动站--初始化最新时间

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"observTime"});
            dataBySelect.setSort(new String[]{"observTime desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "msgmediumsmallscale");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadSkCounty() {
        // TODO 区域自动站--加载县信息

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"county"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "smallscale_station");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadSkStation() {
        // TODO 区域自动站--加载站点信息
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "smallscale_station");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String MultiElemQueryByTimeRange(HttpServletRequest request) {
        // TODO 区域自动站--多要素查询(地图数据)

        try {
            String timeRange = request.getParameter("timeRange");
            if (timeRange.startsWith("[")) {
                timeRange = timeRange.substring(1, timeRange.length());
            }
            if (timeRange.endsWith("]")) {
                timeRange = timeRange.substring(0, timeRange.length() - 1);
            }
            String strDate1 = timeRange.split(",")[0];// 开始时间
            String strDate2 = timeRange.split(",")[1];// 结束时间

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam("observTime between '" + strDate1 + "' and '" + strDate2
                    + "'and drybulbtemp != -65535 and RelHumidity != -65535 and InstantWindV != -65535 and InstantWindD != -65535 and StationPress != -65535 and Rain != -65535'"
                    + "' and 1=1");
            dataBySelect.setColumns(new String[]{"StationID", "stationname", "Longitude", "Latitude",
                    "CAST (AVG (drybulbtemp) AS NUMERIC (18,1)) AS drybulbtemp",
                    "CAST (AVG (relhumidity) AS NUMERIC (18,1)) AS relhumidity",
                    "CAST (MAX (instantwindv) AS NUMERIC (18,1)) AS instantwindv",
                    "CAST (MAX (instantwindd) AS NUMERIC (18,1)) AS instantwindd",
                    "CAST (AVG (stationpress) AS NUMERIC (18,1)) AS stationpress",
                    "CAST (SUM (rain) AS NUMERIC (18,1)) AS rain"});
            dataBySelect.setSort(new String[]{"StationID"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (DateTime.UserMainDataTable(sdf.parse(strDate2), DbConfig.CACHEDAYS)) {
                map.put("method", "MsgMediumSmallScale");
            } else {
                map.put("method", "MsgMediumSmallScale");
            }
            map.put("sqlType", "select");

            List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
            String message = pc.processRequest(map);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });

            result = "[";
            if (resultList != null && resultList.size() > 0) {
                for (msgmediumsmallscale msg : resultList) {
                    result += "{";
                    result += "\"stationId\":\"" + msg.getStationid().trim() + "\",";
                    result += "\"stationName\":\"" + msg.getStationname().trim() + "\",";
                    result += "\"rain\":\"" + msg.getRain() + "\","; //
                    result += "\"windV\":\"" + msg.getInstantwindv() + "\",";//
                    result += "\"windD\":\"" + WebCtrlData.GetAllFx(msg.getInstantwindd().toString()) + "\",";
                    result += "\"windDVal\":\"" + msg.getInstantwindd() + "\",";
                    result += "\"humid\":\"" + msg.getRelhumidity() + "\",";
                    result += "\"temp\":\"" + msg.getDrybulbtemp() + "\",";
                    result += "\"press\":\"" + msg.getStationpress() + "\",";
                    result += "\"longitude\":\"" + msg.getLongitude() + "\",";
                    result += "\"latitude\":\"" + msg.getLatitude() + "\"";
                    result += "},";
                }
            }
            result = result.subSequence(0, result.length() - 1) + "]";

            if (result.equals("")) {
                result = "[]";
            }


        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String MultiElemQueryByTimeRangeSta(HttpServletRequest request) {
        // TODO 区域自动站--多要素查询（表格数据）
        // !!!!!!!!!!!!!!!
        // 没用到
        try {

            String timeRange = request.getParameter("timeRange");
            if (timeRange.startsWith("[")) {
                timeRange = timeRange.substring(1, timeRange.length());
            }
            if (timeRange.endsWith("]")) {
                timeRange = timeRange.substring(0, timeRange.length() - 1);
            }
            String strDate1 = timeRange.split(",")[0];// 开始时间
            String strDate2 = timeRange.split(",")[1];// 结束时间
            String stationID = request.getParameter("staId");// 站点编号

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "StationID,Longitude,Latitude,stationname,observTime ,rain ,drybulbtemp ,relhumidity ,instantwindv ,instantwindd ,stationpress "});
            dataBySelect.setParam(
                    "observTime BETWEEN  '" + strDate1 + "' and '" + strDate2 + "' and  StationID='" + stationID + "'");
            dataBySelect.setSort(new String[]{"observTime"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (DateTime.UserMainDataTable(sdf.parse(strDate2), DbConfig.CACHEDAYS)) {
                map.put("method", "MsgMediumSmallScale");
            } else {
                map.put("method", "MsgMediumSmallScale");
            }
            map.put("sqlType", "select");

            List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
            String message = pc.processRequest(map);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });

            result = "[";
            if (resultList != null && resultList.size() > 0) {
                for (msgmediumsmallscale msg : resultList) {
                    result += "{";
                    result += "\"stationId\":\"" + msg.getStationid().trim() + "\",";
                    result += "\"stationName\":\"" + msg.getStationname().trim() + "\",";
                    result += "\"rain\":\"" + msg.getRain() + "\","; //
                    result += "\"windV\":\"" + msg.getInstantwindv() + "\",";//
                    result += "\"windD\":\"" + WebCtrlData.GetAllFx(msg.getInstantwindd().toString()) + "\",";
                    result += "\"windDVal\":\"" + msg.getInstantwindd() + "\",";
                    result += "\"humid\":\"" + msg.getRelhumidity() + "\",";
                    result += "\"temp\":\"" + msg.getDrybulbtemp() + "\",";
                    result += "\"press\":\"" + msg.getStationpress() + "\",";
                    result += "\"longitude\":\"" + msg.getLongitude() + "\",";
                    result += "\"latitude\":\"" + msg.getLatitude() + "\"";
                    result += "},";
                }
            }
            result = result.subSequence(0, result.length() - 1) + "]";

            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String SmallScaleByTimeRangeSta(HttpServletRequest request) {
        // TODO 区域自动站--信息查询
        String stationIDs = request.getParameter("staIds");// 站点编号
        String county = request.getParameter("county"); // 所属县
        List<msgmediumsmallscale> msgmediumsmallscales = new ArrayList<msgmediumsmallscale>();
        Date observTime = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
        String obsTime = df.format(new Date());
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(
                    new String[]{"stationID,stationName,city,observTime,longitude,latitude,instantWindD,instantWindV ,rain,dryBulbTemp,relHumidity,stationPress"});
            dataBySelect.setSort(new String[]{"observTime desc"});
            if (!StringUtil.IsNullOrEmpty(stationIDs)) {
                dataBySelect.setParam(" StationID in ('" + stationIDs.replace(",", "','") + "') and  observTime = '" + obsTime + "'");
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "msgmediumsmallscale");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result != null && result.length() > 0) {
                try {
                    msgmediumsmallscales = JsonUtil.jsonStr2TypeReference(result,
                            new TypeReference<List<msgmediumsmallscale>>() {
                            });
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (msgmediumsmallscales != null && msgmediumsmallscales.size() > 0) {
                    for (msgmediumsmallscale m : msgmediumsmallscales) {
                        observTime = m.getObservtime();
                        RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
                        Map<String, String> map1 = new HashMap<String, String>();
                        String result1 = "";
                        if (!StringUtil.IsNullOrEmpty(county)) {
                            dataBySelect1.setColumns(new String[]{
                                    "stationID,stationName,city,observTime,longitude,latitude,instantWindD,instantWindV ,rain,dryBulbTemp,relHumidity,stationPress"});
                            dataBySelect1
                                    .setParam("observtime='" + observTime + "' and county like '%" + county + "%'");
                            dataBySelect1.setSort(new String[]{"observTime,StationID"});
                            map1.put("method", "msgmediumsmallscale");
                        } else {
                            dataBySelect1.setColumns(new String[]{
                                    " stationID,stationName,city,observTime,longitude,latitude,instantWindD,instantWindV,rain,dryBulbTemp,relHumidity,stationPress"});
                            dataBySelect1.setParam("observtime='" + observTime + "'");
                            dataBySelect1.setSort(new String[]{"observTime,StationID"});
                            map1.put("method", "msgmediumsmallscale");
                        }
                        result1 = pc.processRequest(map1);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitCityMaxTime() {
        // TODO 城镇预报最新时间
        // 没用到
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setSort(new String[]{"datechar desc,timeChar desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "ForecastInfoTemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadCityStation() {
        // TODO 城镇预报站点信息
        // 没用到
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setParam("flag='地面'");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "special_srv_station");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<special_srv_station> list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<special_srv_station>>() {
            });

            if (list != null && list.size() > 0) {
                result = "[";
                for (special_srv_station rs : list) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid() + "\",";
                    result += "\"stationName\":\"" + rs.getStationname() + "\",";
                    result += "\"province\":\"" + rs.getProvince() + "\","; //
                    result += "\"city\":\"" + rs.getCity() + "\",";//
                    result += "\"county\":\"" + WebCtrlData.GetAllFx(rs.getCounty()) + "\",";
                    result += "\"flag\":\"" + rs.getFlag() + "\",";
                    result += "\"longitude\":\"" + rs.getLongitude() + "\",";
                    result += "\"latitude\":\"" + rs.getLatitude() + "\"";
                    result += "},";
                }
                result = result.subSequence(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String CityForecast(HttpServletRequest request) {
        // TODO 城镇报查询

        // ###############

        String strDate = request.getParameter("date") + " 00:00:00"; // 预报时间
        String strTime = request.getParameter("sc"); // 预报时次
        String NTimes = request.getParameter("sx"); // 时效
        String county = request.getParameter("county"); // 所属县

        try {
            WebCtrlData web = new WebCtrlData();
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"StationID , StationName ,city ,county ,"
                    + "DateChar ,TimeChar ,nTimes ," + "Longitude , Latitude , altitude ,"
                    + "Weather2 , Weather1 ,cast(MaxTemp As Decimal(10, 1)) , "
                    + "cast(MinTemp As Decimal(10, 1)) , Wind1 , Wind2 , " + "WindD1 , WindD2 "});
            dataBySelect.setParam("DateChar = '" + strDate + "' AND TimeChar = '" + strTime + "' AND NTimes = '"
                    + NTimes + "' " + "and county like '" + county + "%' ");
            dataBySelect.setSort(new String[]{"StationID"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "ForecastInfoTemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);

            String message = pc.processRequest(map);
            List<forecastinfotemp> forecast = new ArrayList<forecastinfotemp>();
            forecast = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "[";
                for (forecastinfotemp temp : forecast) {
                    result += "{";
                    result += "\"stationId\":\"" + temp.getStationid() + "\",";
                    result += "\"stationName\":\"" + temp.getStationname().trim() + "\",";
                    result += "\"city\":\"" + temp.getCity().trim() + "\","; //
                    result += "\"county\":\"" + temp.getCounty().trim() + "\",";//
                    result += "\"forcastDate\":\"" + new DateTime(temp.getDatechar()).toDateString().trim() + "\",";
                    result += "\"forcastSc\":\"" + temp.getTimechar().trim() + "\",";
                    result += "\"forcastSx\":\"" + temp.getNtimes().toString().trim() + "\",";
                    String strMinTemp = temp.getMintemp().toString().trim();
                    String strMaxTemp = temp.getMaxtemp().toString().trim();
                    if (strMinTemp.equals("-65535.0") || strMinTemp.equals("65535.0")) {
                        strMinTemp = "";
                    }
                    if (strMaxTemp.equals("-65535.0") || strMaxTemp.equals("65535.0")) {
                        strMaxTemp = "";
                    }
                    result += "\"maxTemp\":\"" + strMaxTemp + "\",";
                    result += "\"minTemp\":\"" + strMinTemp + "\",";
                    // Wind1 AS 最小风速, Wind2 AS 最大风速, " + "WindD1 AS 最小风向, WindD2 AS 最大风向
                    String strWindDir1 = temp.getWind1().toString().trim();
                    String strWindDir2 = temp.getWind2().toString().trim();
                    strWindDir1 = WebCtrlData.GetAllFx(
                                    String.format("%02d", Integer.parseInt(strWindDir1 == "-65535" ? "0" : strWindDir1)))
                            .toString();
                    strWindDir2 = WebCtrlData.GetAllFx(
                                    String.format("%02d", Integer.parseInt(strWindDir2 == "-65535" ? "0" : strWindDir2)))
                            .toString();

                    if (!strWindDir1.equals(strWindDir2))
                        strWindDir1 = strWindDir1 + "转" + strWindDir2;
                    result += "\"windD\":\"" + strWindDir1 + "\","; //
                    String strMinWind = temp.getWindd1().toString().trim();
                    int minWind = Integer.parseInt(strMinWind == "-65535" ? "0" : strMinWind);
                    String minWindS = String.format("%02d", minWind);

                    String strMaxWind = temp.getWindd2().toString().trim();
                    int maxWind = Integer.parseInt(strMaxWind == "-65535" ? "0" : strMaxWind);
                    String maxWindS = String.format("%02d", maxWind);
                    String strWindDisp = "";
                    if (minWindS == maxWindS)
                        strWindDisp = web.GetWeatherFs(minWindS);
                    else
                        strWindDisp = web.GetWeatherFs(minWindS) + " 转 " + web.GetWeatherFs(maxWindS);
                    result += "\"windV\":\"" + strWindDisp + "\",";//
                    String strWeather1 = temp.getWeather1().toString().trim();
                    String strWeather2 = temp.getWeather1().toString().trim();
                    strWeather1 = String.format("%02d", Integer.parseInt(strWeather1 == "-65535" ? "0" : strWeather1));
                    strWeather2 = String.format("%02d", Integer.parseInt(strWeather2 == "-65535" ? "0" : strWeather2));
                    String strWeatherDisp = "";
                    if (strWeather1.equals(strWeather2))
                        strWeatherDisp = WebCtrlData.WeatherNameToPicPath(strWeather1);
                    else
                        strWeatherDisp = WebCtrlData.WeatherNameToPicPath(strWeather1) + "转"
                                + WebCtrlData.WeatherNameToPicPath(strWeather2);
                    result += "\"weatherCode1\":\"" + strWeather1 + "\",";
                    result += "\"weatherCode2\":\"" + strWeather2 + "\",";
                    result += "\"WeatherPhenomena\":\"" + strWeatherDisp + "\",";
                    // "Longitude AS 经度, Latitude AS 纬度, altitude as 海拔
                    result += "\"longitude\":\"" + temp.getLongitude() + "\",";
                    result += "\"latitude\":\"" + temp.getLatitude() + "\",";
                    result += "\"altitude\":\"" + Double.parseDouble(
                            temp.getAltitude().toString() == "" ? "0" : temp.getAltitude().toString()) + "\"";
                    result += "},";
                }
                result = result.subSequence(0, result.length() - 1) + "]";
            }
            if (result.equals("")) {
                result = "[]";
            }


        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;

    }

    @Override
    public String CityForecastByTimeRangeSta(HttpServletRequest request) {

        // TODO 城镇报查询
        String strDate = request.getParameter("date") + " 00:00:00"; // 预报时间
        String strTime = request.getParameter("sc"); // 预报时次
        String NTimes = request.getParameter("sx"); // 时效
        String county = request.getParameter("county"); // 所属县

        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"StationID AS 站点编号, StationName AS 站点名称, city 市,county 县,"
                    + "(datechar + cast((ntimes-24)||'hours' as interval)) as 预报时间,TimeChar as 预报时次,nTimes as 预报时效,"
                    + "Longitude AS 经度, Latitude AS 纬度, altitude as 海拔,"
                    + "Weather2 AS 天气现象2, Weather1 AS 天气现象1,cast(MaxTemp As Decimal(10, 1)) AS 最高温度, "
                    + "cast(MinTemp As Decimal(10, 1)) AS 最低温度, Wind1 AS 最大风速, Wind2 AS 最小风速, "
                    + "WindD1 AS 最小风向, WindD2 AS 最大风向 "});
            dataBySelect.setParam("datechar= '" + strDate.substring(0, 10) + "' and  timechar= '"
                    + String.format("%02d", strTime) + "'" + "and county like '" + county + "%'");
            dataBySelect.setSort(new String[]{"  ORDER BY StationID,datechar,ntimes"});
            map.put("param", JsonUtil.object2Json(dataBySelect));

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (DateTime.UserMainDataTable(sdf.parse(strDate), 10)) {
                map.put("method", "ForecastInfoTemp");
            } else {
                map.put("method", "ForecastInfo");
            }

            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitFineMaxTime() {
        // TODO 精细化预报最新时间
        // 没用到
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setSort(new String[]{"order by datechar desc,timeChar desc"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "township_forecasttemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadFineStation() {
        // TODO 精细化预报站点信息
        // 没用到
        try {

            // ????????????????
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "township_station");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<township_station> townlist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<township_station>>() {
            });


            // 执行查询
            if (townlist != null && townlist.size() > 0) {
                result = "[";
                for (township_station rs : townlist) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid() + "\",";
                    result += "\"stationName\":\"" + rs.getStationname() + "\",";
                    result += "\"city\":\"" + rs.getCity() + "\",";//
                    result += "\"areaName\":\"" + rs.getAreaname() + "\","; //
                    result += "\"longitude\":\"" + rs.getLongitude() + "\",";
                    result += "\"latitude\":\"" + rs.getLatitude() + "\"";
                    result += "\"altitude\":\""
                            + Double.parseDouble(rs.getAltitude() + "" == "" ? "0" : rs.getAltitude() + "")
                            + "\"";
                    result += "},";
                }
                result = result.subSequence(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String ObtainSatellite(HttpServletRequest request) {
        // TODO 云图查询
        String timeRange = request.getParameter("timeRange");
        if (timeRange.startsWith("[")) {
            timeRange = timeRange.substring(1, timeRange.length());
        }
        if (timeRange.endsWith("]")) {
            timeRange = timeRange.substring(0, timeRange.length() - 1);
        }
        String strDate1 = timeRange.split(",")[0];// 开始时间
        String strDate2 = timeRange.split(",")[1];// 结束时间
        String strtype = request.getParameter("type");// 类型

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(
                    "CAST (datechar AS TIMESTAMP) CAST (SUBSTRING (TimeChar,1,2) || ' hour' AS INTERVAL)) CAST (SUBSTRING (TimeChar,2,3) || 'minute' AS INTERVAL)  between '"
                            + strDate1 + "' and '" + strDate2 + "'  and 1=1");
            dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
            if (!StringUtil.IsNullOrEmpty(strtype)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ytType ='" + strtype + "'"));
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "SatelliteNephoram");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<satellitenephoram> phoram = new ArrayList<satellitenephoram>();
            phoram = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<satellitenephoram>>() {
            });
            String urls = "http://" + request.getServerName() + ":" + request.getServerPort()
                    + request.getContextPath();
            String weburl = urls + "/download?";
            result = "[";
            if (phoram != null && phoram.size() > 0) {
                for (satellitenephoram sa : phoram) {
                    result += "{";
                    result += "\"dateChar\":\"" + sa.getDatechar() + "\",";
                    result += "\"timeChar\":\"" + sa.getTimechar() + "\",";
                    result += "\"type\":\"" + sa.getYttype() + "\",";//
                    String param = "collectionName=yt_jpg_file&datechar="
                            + new DateTime(sa.getDatechar()).toDateTimeString("yyyy-MM-dd").trim() + "&timechar="
                            + sa.getTimechar().trim() + "&yttype=" + sa.getYttype().trim();
                    result += "\"path\":\"" + weburl + param.replace("yt_jpg_file", "yt_file") + "\",";
                    result += "\"jwImgPath\":\"" + weburl + param.replace("yt_jpg_file", "yt_png_file")
                            + "&resultType=binary" + "\",";
                    result += "\"lbImgPath\":\"" + weburl + param + "&resultType=binary" + "\",";
                    result += "\"cloudTitle\":\"" + sa.getSatetitle() + "\"";
                    result += "},";
                }
                result = result.subSequence(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String Warning(HttpServletRequest request) {
        // TODO 预警信息查询

        try {
            String yjLevel = "";
            String color = "";
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String type = request.getParameter("type"); // 预警类型
            String level = request.getParameter("level"); // 预警等级
            String bFree = request.getParameter("bFree"); // 是否解除

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(
                    "AnnouncedTime BETWEEN '" + strDate1 + "' AND '" + strDate2 + "' AND 1=1 AND 2=2 AND 3=3");

            if (!StringUtil.IsNullOrEmpty(type) && !type.equals("全部")) {
                dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "Type LIKE '%" + type + "%'"));
            }

            if (!StringUtil.IsNullOrEmpty(level) && !level.equals("全部")) {
                dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "Color LIKE '%" + level + "%'"));
            }
            if (!StringUtil.IsNullOrEmpty(bFree)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "bFree='" + bFree + "'"));
            }
            dataBySelect.setSort(new String[]{"AnnouncedTime DESC"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "warn_signal_info");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<warn_signal_info> infos = new ArrayList<warn_signal_info>();
            infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<warn_signal_info>>() {
            });

            // 执行查询

            result = "[";
            if (infos != null && infos.size() > 0) {
                for (warn_signal_info info : infos) {
                    result += "{";
                    result += "\"id\":\"" + info.getId() + "\",";
                    result += "\"area\":\"" + info.getArea() + "\",";
                    result += "\"type\":\"" + info.getType() + "\",";//
                    yjLevel = info.getColor();
                    switch (yjLevel) {
                        case "红色":
                            color = "255";
                            break;
                        case "橙色":
                            color = "42495";
                            break;
                        case "黄色":
                            color = "65535";
                            break;
                        case "蓝色":
                            color = "16711680";
                            break;
                    }
                    result += "\"level\":\"" + yjLevel + "\",";
                    result += "\"color\":\"" + color + "\",";
                    result += "\"county\":\"" + info.getCounty() + "\",";
                    result += "\"standard\":\"" + info.getStandard() + "\",";
                    result += "\"defenseGuide\":\"" + info.getDefenseguide() + "\",";
                    result += "\"announcedTime\":\""
                            + new DateTime(info.getAnnouncedtime()).toDateTimeString("yyyy-MM-dd HH:mm:ss") + "\",";
                    result += "\"signatory\":\"" + info.getSignatory() + "\",";
                    result += "\"watch\":\"" + info.getWatch() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"bFree\":\"" + info.getBfree() + "\",";
                    result += "\"jcpath\":\"" + info.getJcpath() + "\",";
                    result += "\"y2path\":\"" + info.getY2path() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"jb\":\"" + Integer.parseInt(info.getJb().toString()) + "\"";
                    result += "},";
                }
                result = result.subSequence(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String InitTourStation(HttpServletRequest request) {
        // TODO 旅游气象景点信息

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "tour_stations");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<tour_stations> tlist = JsonUtil.jsonStr2TypeReference(result,
                    new TypeReference<List<tour_stations>>() {
                    });

            String urls = "http://" + request.getServerName() + ":" + request.getServerPort()
                    + request.getContextPath();
            String weburl = urls + "/download?";
//			// 执行查询

            if (tlist.size() > 0) {

//				rs.previous();

                result = "[";
                for (tour_stations t : tlist) {
                    result += "{";
                    result += "\"stationID\":\"" + t.getStationid() + "\",";
                    result += "\"stationName\":\"" + t.getStationname() + "\",";
                    result += "\"altitude\":\"" + t.getAltitude() + "\",";
                    result += "\"text\":\"" + t.getText().replace("\r", "\\r").replace("\n", "\\n").replace("\"", "\'")
                            + "\",";
                    result += "\"imageMap\":\"" + weburl + "collectionName=image_file&stationid="
                            + t.getStationid().trim() + "\",";
                    result += "\"areaName\":\"" + t.getAreaname() + "\",";
                    result += "\"grade\":\"" + t.getGrade() + "\",";
                    result += "\"location\":\"" + t.getLocation() + "\",";
                    result += "\"people\":\"" + t.getPeople() + "\",";
                    result += "\"phone\":\"" + t.getPhone() + "\",";
                    result += "\"suggest\":\"" + t.getSuggest() + "\",";
                    result += "\"longitude\":\"" + t.getLongitude() + "\",";
                    result += "\"latitude\":\"" + t.getLatitude() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadTourCounty() {
        // TODO 旅游气象景点信息

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"AreaName"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "tour_stations");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String TourForecastSta(HttpServletRequest request) {
        // TODO 旅游预报信息
        String strDate = request.getParameter("date") + " 00:00:00"; // 预报时间

        String strTime = request.getParameter("sc"); // 预报时次
        String NTimes = request.getParameter("sx"); // 时效
        String stationID = request.getParameter("staId"); // 站号

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setParam("DateChar = '" + strDate + "' AND TimeChar = '" + strTime + "' AND NTimes = '"
                    + NTimes + "' and stationid = '" + stationID + "'");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "tour_fcst");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String TourForecastSta_7Day(HttpServletRequest request) {
        // TODO 旅游预报信息
        // ?????????????????????????????
        String stationID = request.getParameter("staId");
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            columns.add("DateChar");
            selectRequest.setColumns(columns.toArray(new String[columns.size()]));
            selectRequest.setLimit(1);
            selectRequest.setSort(new String[]{"DateChar desc"});
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<tour_fcst> tour1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_fcst>>() {
            });

            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            columns = new ArrayList<String>();
            selectRequest.setLimit(1);
            selectRequest.setSort(new String[]{"DateChar desc", "ntimes desc"});
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message2 = pc.processRequest(selectParam);
            List<tour_fcst> tour2 = JsonUtil.jsonStr2TypeReference(message2, new TypeReference<List<tour_fcst>>() {
            });

            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            columns = new ArrayList<String>();
            columns.add("DateChar");
            selectRequest.setColumns(columns.toArray(new String[columns.size()]));
            selectRequest.setLimit(7);
            selectRequest.setSort(new String[]{"DateChar desc", "ntimes desc", "timechar desc"});
            StringBuilder builder = new StringBuilder();
            int whereCount = 0;
            if (tour1 != null && tour1.size() > 0) {
                builder.append(String.format("DateChar = '%s'", tour1.get(0).getDatechar()));
                whereCount++;
            }
            if (tour2 != null && tour2.size() > 0) {
                builder.append(String.format(" and TimeChar = '%s'", tour2.get(0).getTimechar()));
            }
            if (!StringUtil.IsNullOrEmpty(stationID)) {
                builder.append(String.format(" and stationid = '%s'", stationID));
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(builder.toString())) {
                builder = builder.replace(0, 4, "");
            }
            selectRequest.setParam(builder.toString());
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message3 = pc.processRequest(selectParam);
            List<tour_fcst> tour3 = JsonUtil.jsonStr2TypeReference(message3, new TypeReference<List<tour_fcst>>() {
            });


            DateTime date = new DateTime();
            WebCtrlData web = new WebCtrlData();
            if (tour3 != null && tour3.size() > 0) {
                result = "[";
                for (tour_fcst rs : tour3) {
                    date = new DateTime(rs.getDatechar());
                    result += "{";
                    SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
                    String week = dateFm.format(date.toDate());
                    String strDateTime = date.GetDay() + "日" + week;
                    result += "\"Date\":\"" + strDateTime + "\",";
                    result += "\"dateChar\":\"" + rs.getDatechar() + "\",";
                    result += "\"timeChar\":\"" + rs.getTimechar() + "\",";
                    String strLvYouTianQi = rs.getWeather1().trim();
                    String[] strWeathers = strLvYouTianQi.split("转");
                    String strWeather1 = "";
                    String strWeather2 = "";
                    if (strWeathers.length == 2) {
                        strWeather1 = WebCtrlData.WeatherNameToPicPath(strWeathers[0]);
                        strWeather2 = WebCtrlData.WeatherNameToPicPath(strWeathers[1]);
                    }

                    if (strWeather1.equals(strWeather2)) {
                        strLvYouTianQi = strWeathers[0];
                        strWeather1 = WebCtrlData.WeatherNameToPicPath(strWeathers[0]);
                        strWeather2 = WebCtrlData.WeatherNameToPicPath(strWeathers[0]);
                    }
                    result += "\"WeatherPhenomena\":\"" + strLvYouTianQi + "\",";
                    result += "\"weatherCode1\":\"" + strWeather1 + "\",";
                    result += "\"weatherCode2\":\"" + strWeather2 + "\",";
                    result += "\"maxTemp\":\"" + rs.getMaxtemp() + "\",";
                    result += "\"minTemp\":\"" + rs.getMintemp() + "\",";
                    result += "\"windD\":\"" + WebCtrlData.GetAllFx(rs.getWindd().trim()) + "\",";
                    double Wind = Double.parseDouble(rs.getWinds()); // 风速
                    String WindS = web.GetWeatherFs(WebCtrlData.FengSuToFengJi(Wind) + "");
                    result += "\"windV\":\"" + WindS + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String TourSmallScaleSta_24Hour(HttpServletRequest request) {
        // TODO 旅游预报信息
        try {
            String stationID = request.getParameter("staId"); // 站号
            String[] tongji = new String[]{"", "", "", "", ""};

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(
                    new String[]{"StationID,Longitude,Latitude,stationname,observTime,rain AS 雨量,drybulbtemp AS 空气温度,"
                            + "relhumidity AS 相对湿度,instantwindv AS 风速,stationpress AS 本站气压"});
            dataBySelect.setParam("StationID = '" + stationID + "'");
            dataBySelect.setSort(new String[]{" ORDER BY observtime"});
            dataBySelect.setLimit(24);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "tour_smallscale");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;

    }

    @Override
    public String TourForecastByTimeRangeSta(HttpServletRequest request) {
        // TODO 旅游预报信息
        // 11111111111111111111111111111111111
        String date = request.getParameter("date");
        String stationIDs = request.getParameter("staIds"); // 站号
        int sc = (DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20) ? 8 : 20;

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setParam("datechar='" + DateTime.parseDateTime(date).toDateString() + "' and timechar='"
                    + String.format("%02d", sc));
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "tour_fcst");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String GetNewestForecastInfo() {
        // 新加的url!!!!!!!!!!!!!!
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setSort(new String[]{"datechar desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "hxyj_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<hxyj_warning> listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<hxyj_warning>>() {
            });

            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (hxyj_warning rs : listData1) {
                    result += "{";
                    result += "\"docid\":\"" + rs.getDocid() + "\",";
                    result += "\"dateChar\":\"" + rs.getDatechar() + "\",";
                    result += "\"gradeArea1\":\"" + rs.getGradearea1() + "\",";
                    result += "\"gradeArea2\":\"" + rs.getGradearea2() + "\",";
                    result += "\"gradeArea3\":\"" + rs.getGradearea3() + "\",";
                    result += "\"gradeArea4\":\"" + rs.getGradearea4() + "\",";
                    result += "\"gradeArea5\":\"" + rs.getGradearea5() + "\",";
                    result += "\"pos\":" + JsonUtil.object2Json(WebCtrlData.GetJWWarningPos(rs.getPos())) + ",";
                    result += "\"docpath\":\"" + rs.getDocpath() + "\",";
                    result += "\"foreType\":\"" + rs.getForetype() + "\",";
                    result += "\"warningType\":\"" + rs.getWarningtype() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getFireForecast(HttpServletRequest request) {
        // TODO 森林火险预报查询
        try {
            String fireLevel = "", color = "";
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam("datechar between '" + strDate1 + "' and '\" + strDate2 + '");
            dataBySelect.setSort(new String[]{"order by datechar desc"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "hxyj_warning");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getFireForecastById(HttpServletRequest request) {
        // TODO 森林火险预报(地图显示) 编号
        try {
            String docid = request.getParameter("docid");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"pos,gradearea3,gradearea4,gradearea5,datechar"});
            dataBySelect.setParam("docid='" + docid + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "HXYJ_Warning");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getFireHistory(HttpServletRequest request) {
        try {
            String starttime = request.getParameter("starttime");
            String endtime = request.getParameter("endtime");
            starttime = starttime + " 00:00:00";
            endtime = endtime + " 23:59:59";
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam("AnnouncedTime between '" + starttime + "' and '" + endtime + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "fire_history");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<fire_history> flist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<fire_history>>() {
            });

            if (flist.size() > 0) {
//				rs.previous();
                result = "[";
                for (fire_history f : flist) {
                    result += "{";
                    result += "\"fireName\":\"" + f.getFirename() + "\",";
                    result += "\"address\":\"" + f.getAddress() + "\",";
                    result += "\"announcedTime\":\"" + new DateTime(f.getAnnouncedtime()).toDateString() + "\",";
                    result += "\"disasterArea\":\"" + f.getDisasterarea() + "\",";
                    result += "\"popThreat\":\"" + f.getPopthreat() + "\",";
                    result += "\"propertyThreat\":\"" + f.getPropertythreat() + "\",";
                    result += "\"remarks\":\"" + f.getRemarks() + "\",";
                    result += "\"stationName\":\"" + f.getStationname() + "\",";
                    result += "\"videoPath\":\"" + f.getVideopath() + "\",";
                    result += "\"longitude\":\"" + f.getLongitude() + "\",";
                    result += "\"latitude\":\"" + f.getLatitude() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String GetNewestDisasterInfo(HttpServletRequest request) {
        // TODO 地灾预警
        String type = request.getParameter("type");
        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"docid,datechar,pos,docpath,warningtype"});
            dataBySelect.setSort(new String[]{"DateChar desc,docid desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            if (type.equals("dz")) {
                map.put("method", "dz_warning");
                map.put("sqlType", "select");
                result = pc.processRequest(map);
            } else if (type.equals("sl")) {
                map.put("method", "sl_warning");
                map.put("sqlType", "select");
                result = pc.processRequest(map);
            } else if (type.equals("forest")) {
                map.put("method", "hxyj_warning");
                map.put("sqlType", "select");
                result = pc.processRequest(map);
            }

            if (result.equals("")) {
                result = "[]";
            }
            List<dz_warning> dzWarningList = JsonUtil.jsonStr2TypeReference(result,
                    new TypeReference<List<dz_warning>>() {
                    });
            if (dzWarningList.size() > 0) {
                result = "[";
                for (dz_warning d : dzWarningList) {
                    WaringPoss wp = GetDotSetByString(d.getPos());// 区坐标信息
                    String strtext = ""; // 导出字符串
                    strtext = wp.Poss;
                    String str = strtext.split(";")[0];
                    String x = "0", y = "0";
                    x = str.split(",")[0];
                    y = str.split(",")[1];
                    String cols = "";
                    cols = wp.arr;
                    result += "{";
                    result += "\"docid\":\"" + d.getDocid() + "\",";
                    result += "\"datechar\":\"" + d.getDatechar() + "\",";
                    result += "\"docpath\":\"" + d.getDocpath() + "\",";
                    result += "\"Color\":\"" + cols + "\",";
                    result += "\"x\":\"" + x + "\",";
                    result += "\"y\":\"" + y + "\",";
                    result += "\"Poss\":\"" + strtext.replace(" ", ",") + "\",";
                    result += "\"warningtype\":\"" + d.getWarningtype() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getDZWarning(HttpServletRequest request) {
        // TODO 地灾预警
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setParam("DateChar between '" + strDate1 + "' and '" + strDate2);
            dataBySelect.setSort(new String[]{"DateChar desc"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "dz_warning");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getDZWarningById(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 地灾预警查询(地图显示) 编号
        try {
            String docid = request.getParameter("docid");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"pos,gradearea3,gradearea4,gradearea5,datechar"});
            dataBySelect.setParam("docid='" + docid + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "DZ_Warning");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String DzPolygon(HttpServletRequest request) {
        try {
            String pos = request.getParameter("pos");
            WaringPoss wp = GetDotSetByString(pos);// 区坐标信息
            String strtext = ""; // 导出字符串
            strtext = wp.Poss;
            String str = strtext.split(";")[0];
            String x = "0", y = "0";
            x = str.split(" ")[0];
            y = str.split(" ")[1];
            String cols = "";
            cols = wp.arr;
            result = "[{\"Color\":\"" + cols + "\",\"x\":\"" + x + "\",\"y\":\"" + y + "\",\"Poss\":\""
                    + strtext.substring(0, strtext.length()) + "\"}]";// 区坐标信息
        } catch (Exception e) {

        }
        return result;
    }

    @Override
    public String DisType() {
        // TODO 地灾类型
        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"disastertypeid,disastername"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "disaster_type");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String IndustryQuery(HttpServletRequest request) {
        // TODO 灾点查询

        // 数据库没有这个数据表！！！！！！！！！！！！！
        try {
            String type = request.getParameter("type");

            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<String, String>();
            selectRequest.setColumns(new String[]{"NAME ,xcoordinate,ycoordinate,lon,lat,scalelevel,geographicposition,threatpopulation,threatproperty,gridcode,layers,disasterlevel"});
            selectRequest.setSort(new String[]{"DateChar desc,docid desc"});
            selectRequest.setLimit(1);
            if (!StringUtil.IsNullOrEmpty(type) && type != "all") {
                selectRequest.setParam("Layers='" + type + "'");
            }
            selectParam.put("method", "disaster_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<DisasterPoint> disasterPoints = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<DisasterPoint>>() {
            });

            if (disasterPoints != null && disasterPoints.size() > 0) {
                result = "[";
                for (DisasterPoint rs : disasterPoints) {
//                    result += "{";
//                    result += "\"name\":\"" + rs.getString("NAME") + "\",";
//                    result += "\"gridCode\":\"" + rs.getString("gridcode") + "\"";
//                    result += "\"disasterScale\":\"" + rs.getString("scalelevel") + "\"";
//                    result += "\"adress\":\"" + rs.getString("geographicposition") + "\"";
//                    result += "\"popThreat\":\"" + rs.getString("threatpopulation") + "\"";
//                    result += "\"propertyThreat\":\"" + rs.getString("threatproperty") + "\"";
//                    result += "\"layers\":\"" + rs.getString("Layers") + "\"";
//                    result += "\"zqGrade\":\"" + rs.getString("disasterlevel") + "\"";
//                    result += "\"longitude\":\"" + rs.getString("lon") + "\"";
//                    result += "\"latitude\":\"" + rs.getString("lat") + "\"";
//                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitTrafficMaxTime() {
        // TODO 交通气象--初始化最新时间
        Connection conn = null;
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"AnnouncedTime"});
            dataBySelect.setSort(new String[]{"order by AnnouncedTime desc"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "Traffic");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getTrafficForcast(HttpServletRequest request) {
        // TODO 交通气象查询

        try {
            String ybsj = request.getParameter("date");
            String strDate1 = ybsj + " 00:00:01";
            String strDate2 = ybsj + " 23:59:59";

            String strdj = "";// 预报等级
            String strsz = "";// 代表颜色
            String strname = "";// 代表颜色

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "announcedtime,ForcastLevel,ViewLevel,Weather12,MinTemp,MaxTemp,Wind,WindD,trafficsid"});
            dataBySelect.setParam("announcedtime>='" + strDate1 + "' and announcedtime<='" + strDate2 + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "Traffic");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<traffic> list = new ArrayList<traffic>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<traffic>>() {
            });

            if (list.size() > 0) {
                result = "[";
                String result1 = "";
                for (traffic t : list) {
                    RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
                    dataBySelect1.setColumns(new String[]{"stationname,longitude,latitude,roadcoordinate"});
                    dataBySelect1.setParam("stationid='" + t.getTrafficsid() + "'");
                    Map<String, String> map1 = new HashMap<String, String>();
                    map1.put("param", JsonUtil.object2Json(dataBySelect1));
                    map1.put("method", "traffic_weather_sta");
                    map1.put("sqlType", "select");
                    result1 = pc.processRequest(map1);
                    if (result1.equals("")) {
                        result1 = "[]";
                    }
                    List<traffic_weather_sta> list1 = new ArrayList<traffic_weather_sta>();
                    list1 = JsonUtil.jsonStr2TypeReference(result1, new TypeReference<List<traffic_weather_sta>>() {
                    });
                    for (traffic_weather_sta t1 : list1) {
                        strname = t1.getStationname().trim(); // 名称
                        strdj = t.getForcastlevel().toString().trim(); // 等级
                        // 等级 根据不同的等级及得到的路段坐标集画路线，不同颜色表示不同道路。
                        if (strdj.equals("1")) {
                            strsz = "#71cb46"; // 绿色，表示路况很好
                            strdj = "路况很好";
                        } else if (strdj.equals("2")) {
                            strsz = "#feff00"; // 黄绿色，表示路况一般
                            strdj = "路况一般";
                        } else if (strdj.equals("3")) {
                            strsz = "#ffb7b8"; // 黄色，表示路况较差
                            strdj = "路况较差";
                        } else if (strdj.equals("4")) {
                            strsz = "#fb3d3f"; // 深橘黄色，表示路况不好
                            strdj = "路况不好";
                        } else if (strdj.equals("5")) {
                            strsz = "#bb0200"; // 深红色，表示路况很差
                            strdj = "路况很差";
                        }

                        try {
                            result += "{";
                            result += "\"announcedTime\":\"" + new DateTime(t.getAnnouncedtime()).toDateString()
                                    + "\",";
                            // result += "\"poss\":\"" + Poss + "\",";
                            // result += "\"possJw\":\"" + strpos + "\",";
                            result += "\"name\":\"" + strname + "\",";
                            result += "\"longitude\":\"" + t1.getLon() + "\",";
                            result += "\"latitude\":\"" + t1.getLat() + "\",";
                            result += "\"dj\":\"" + strdj + "\",";
                            result += "\"viewLevel\":\"" + t.getViewlevel() + "\",";
                            result += "\"clr\":\"" + strsz + "\",";
                            result += "\"tq\":\"" + t.getWeather12() + "\",";
                            result += "\"wendu\":\"" + t.getMintemp() + "℃~" + t.getMaxtemp() + "℃" + "\",";
                            result += "\"windV\":\"" + t.getWind() + "\",";
                            result += "\"windD\":\"" + t.getWindd() + "\"";
                            result += "},";
                        } catch (Exception e) {
                            continue;
                        }
                    }
                }
                result = result.substring(0, result.length() - 1) + "]";

            } else {
                String result2 = "";
                RequestDataBySelect dataBySelect2 = new RequestDataBySelect();
                dataBySelect2.setColumns(new String[]{
                        "announcedtime,ForcastLevel,ViewLevel,Weather12,MinTemp,MaxTemp,Wind,WindD,trafficsid"});
//                dataBySelect2.setParam("announcedtime>='" + strDate1 + "' and announcedtime<='" + strDate2 + "'");
                dataBySelect2.setSort(new String[]{"announcedtime"});
                dataBySelect2.setLimit(1);
                Map<String, String> map2 = new HashMap<String, String>();
                map2.put("param", JsonUtil.object2Json(dataBySelect2));
                map2.put("method", "Traffic");
                map2.put("sqlType", "select");
                result2 = pc.processRequest(map2);
                if (result2.equals("")) {
                    result2 = "[]";
                }

                List<traffic> list2 = new ArrayList<traffic>();
                list2 = JsonUtil.jsonStr2TypeReference(result2, new TypeReference<List<traffic>>() {
                });

                if (list2.size() > 0) {
                    String result3 = "";
                    result = "[";
                    for (traffic t : list2) {
                        RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
                        dataBySelect1.setColumns(new String[]{"stationname,longitude,latitude,roadcoordinate"});
                        dataBySelect1.setParam("stationid='" + t.getTrafficsid() + "'");
                        Map<String, String> map1 = new HashMap<String, String>();
                        map1.put("param", JsonUtil.object2Json(dataBySelect1));
                        map1.put("method", "traffic_weather_sta");
                        map1.put("sqlType", "select");
                        result3 = pc.processRequest(map1);
                        if (result3.equals("")) {
                            result3 = "[]";
                        }
                        List<traffic_weather_sta> list3 = new ArrayList<traffic_weather_sta>();
                        list3 = JsonUtil.jsonStr2TypeReference(result3, new TypeReference<List<traffic_weather_sta>>() {
                        });
                        for (traffic_weather_sta t1 : list3) {
                            strname = t1.getStationname().trim(); // 名称
                            strdj = t.getForcastlevel().toString().trim(); // 等级
                            // 等级 根据不同的等级及得到的路段坐标集画路线，不同颜色表示不同道路。
                            if (strdj.equals("1")) {
                                strsz = "#71cb46"; // 绿色，表示路况很好
                                strdj = "路况很好";
                            } else if (strdj.equals("2")) {
                                strsz = "#feff00"; // 黄绿色，表示路况一般
                                strdj = "路况一般";
                            } else if (strdj.equals("3")) {
                                strsz = "#ffb7b8"; // 黄色，表示路况较差
                                strdj = "路况较差";
                            } else if (strdj.equals("4")) {
                                strsz = "#fb3d3f"; // 深橘黄色，表示路况不好
                                strdj = "路况不好";
                            } else if (strdj.equals("5")) {
                                strsz = "#bb0200"; // 深红色，表示路况很差
                                strdj = "路况很差";
                            }

                            try {
                                result += "{";
                                result += "\"announcedTime\":\"" + new DateTime(t.getAnnouncedtime()).toDateString()
                                        + "\",";
                                // result += "\"poss\":\"" + Poss + "\",";
                                // result += "\"possJw\":\"" + strpos + "\",";
                                result += "\"name\":\"" + strname + "\",";
                                result += "\"longitude\":\"" + t1.getLon() + "\",";
                                result += "\"latitude\":\"" + t1.getLat() + "\",";
                                result += "\"dj\":\"" + strdj + "\",";
                                result += "\"viewLevel\":\"" + t.getViewlevel() + "\",";
                                result += "\"clr\":\"" + strsz + "\",";
                                result += "\"tq\":\"" + t.getWeather12() + "\",";
                                result += "\"wendu\":\"" + t.getMintemp() + "℃~" + t.getMaxtemp() + "℃" + "\",";
                                result += "\"windV\":\"" + t.getWind() + "\",";
                                result += "\"windD\":\"" + t.getWindd() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                continue;
                            }
                        }
                    }
                    result = result.substring(0, result.length() - 1) + "]";
                }
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitCityFireMaxTime() {
        // TODO 城市气象--初始化最新时间

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"forcastdate"});
            dataBySelect.setSort(new String[]{"order by forcastdate desc"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "CSHX_ZSYB");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadCityFireStation() {
        // TODO 城市气象--加载站点信息
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"stationid ,stationname,lon,lat"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "CSHX_ZSYB");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getCityFire(HttpServletRequest request) {
        // TODO 城市气象预报查询
        try {
            String date = request.getParameter("date");
            String stationIDs = request.getParameter("staIds");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "stationid,stationname,forcastdate,fireindex,firelevel,humidity,noraincomponent,tempcomponent,windcomponent,raincomponent,lon,lat"});
            dataBySelect.setParam("forcastdate = '" + date + "' ");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "CSHX_ZSYB");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "stationid,stationname,forcastdate,fireindex,firelevel,humidity,noraincomponent,tempcomponent,windcomponent,raincomponent,lon,lat "});
            StringBuilder strWhere = new StringBuilder();
            int whereCount = 0;
            if (!StringUtil.IsNullOrEmpty(date)) {
                strWhere.append(String.format("forcastdate = '%s'", date));
                whereCount++;
            }
            if (!StringUtil.IsNullOrEmpty(stationIDs)) {
                stationIDs = stationIDs.replace(",", "','");
                strWhere.append(" stationid in ('" + stationIDs + "')");
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            dataBySelect.setParam(strWhere.toString());
            Map<String, String> paramMap = new HashMap<String, String>();
            paramMap.put("param", JsonUtil.object2Json(dataBySelect));
            paramMap.put("method", "CSHX_ZSYB");
            paramMap.put("sqlType", "select");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            result = pc.processRequest(paramMap);
            List<cshx_zsyb> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<cshx_zsyb>>() {
            });
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (cshx_zsyb rs : listData1) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid() + "\",";
                    result += "\"stationName\":\"" + rs.getStationname() + "\",";
                    result += "\"date\":\"" + rs.getForcastdate() + "\",";
                    result += "\"temp\":\"" + rs.getTempcomponent() + "\",";
                    result += "\"noRain\":\"" + rs.getNoraincomponent() + "\",";
                    result += "\"humid\":\"" + rs.getHumidity() + "\",";
                    result += "\"wind\":\"" + rs.getWindcomponent() + "\",";
                    result += "\"rain\":\"" + rs.getRaincomponent() + "\",";
                    result += "\"zs\":\"" + rs.getFireindex() + "\",";
                    result += "\"level\":\"" + rs.getFirelevel() + "\",";
                    result += "\"longitude\":\"" + rs.getLon() + "\",";
                    result += "\"latitude\":\"" + rs.getLat() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getCityFireByTimeRangeSta(HttpServletRequest request) {
        // TODO 时间范围、站号
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String stationIDs = request.getParameter("staIds");// 站点编号

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "stationid,stationname,forcastdate,fireindex,firelevel,humidity,noraincomponent,tempcomponent,windcomponent,raincomponent,lon,lat"});
            dataBySelect.setParam("forcastdate between '" + strDate1 + "' and '" + strDate2 + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "CSHX_ZSYB");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{
                    "stationid,stationname,forcastdate,fireindex,firelevel,humidity,noraincomponent,tempcomponent,windcomponent,raincomponent,lon,lat"});
            StringBuilder strWhere = new StringBuilder();
            int whereCount = 0;
            if (!StringUtil.IsNullOrEmpty(strDate1)) {
                strWhere.append(String.format("forcastdate > '%s'", strDate1));
                whereCount++;
            }
            if (!StringUtil.IsNullOrEmpty(strDate2)) {
                strWhere.append(String.format("forcastdate < '%s'", strDate2));
                whereCount++;
            }
            if (!StringUtil.IsNullOrEmpty(stationIDs)) {
                stationIDs = stationIDs.replace(",", "','");
                strWhere.append(" stationid in ('" + stationIDs + "')");
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            dataBySelect.setParam(strWhere.toString());
            Map<String, String> paramMap = new HashMap<String, String>();
            paramMap.put("param", JsonUtil.object2Json(dataBySelect));
            paramMap.put("method", "CSHX_ZSYB");
            paramMap.put("sqlType", "select");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            result = pc.processRequest(paramMap);
            List<cshx_zsyb> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<cshx_zsyb>>() {
            });

            // 执行查询
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (cshx_zsyb rs : listData1) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid() + "\",";
                    result += "\"stationName\":\"" + rs.getStationname() + "\",";
                    result += "\"date\":\"" + rs.getForcastdate() + "\",";
                    result += "\"temp\":\"" + rs.getTempcomponent() + "\",";
                    result += "\"noRain\":\"" + rs.getNoraincomponent() + "\",";
                    result += "\"humid\":\"" + rs.getHumidity() + "\",";
                    result += "\"wind\":\"" + rs.getWindcomponent() + "\",";
                    result += "\"rain\":\"" + rs.getRaincomponent() + "\",";
                    result += "\"zs\":\"" + rs.getFireindex() + "\",";
                    result += "\"level\":\"" + rs.getFirelevel() + "\",";
                    result += "\"longitude\":\"" + rs.getLon() + "\",";
                    result += "\"latitude\":\"" + rs.getLat() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getZsCityName() {
        // TODO 指数信息--获取地区信息

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"cityname"});
            dataBySelect.setParam(" cityid like '5%'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "zhishu");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitZhiSHuForcastMaxTime() {
        // TODO 指数信息最新时间

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"DateChar,TimeChar"});
            dataBySelect.setSort(new String[]{"  order by DateChar desc,TimeChar desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "Zhishu");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            selectRequest.setLimit(1);
            selectRequest.setSort(new String[]{"DateChar desc", "TimeChar desc"});
            columns.add("DateChar");
            columns.add("TimeChar");
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            selectParam.put("method", "zhishu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<zhishu> list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<zhishu>>() {
            });
            if (list != null && list.size() > 0) {
                result = "[{\"newDate\":\"" + new DateTime(list.get(0).getDatechar())
                        + "\",\"newTime\":\"" + list.get(0).getTimechar().trim() + "\"}]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getZsForcastByTimeRange(HttpServletRequest request) {
        // TODO 时间范围、地区名称
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strCityNames = request.getParameter("cityName");// 地区名称

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"CityName,Longitude,Latitude,DateChar,TimeChar,gm,GMGrade,GMText"
                    + ",fy,FYGrade,FYText,shx,SHXGrade,SHXText,xhx,XHXGrade,XHXText,xc,XCGrade,XCText,nyx,NYXGrade,NYXText"
                    + ",ngs,NGSGrade,NGSText,gxb,GXBGrade,GXBText,xjgs,XJGSGrade,XJGSText,gxy,GXYGrade,GXYText,mb,MBGrade,MBText "
                    + ",zz,ZZGrade,ZZText,ls,LSGrade,LSText,ly,LYGrade,LYText,rd,RDGrade,RDText,ss,SSGrade,SSText,pj,PJGrade,PJText"
                    + ",tg,TGGrade,TGText,wr,WRGrade,WRText,zs,ZSGrade,ZSText,cl,CLGrade,CLText,lyou,LYOUGrade,LYOUText,yd,YDGrade,YDText"});
            Map<String, String> map = new HashMap<String, String>();
            StringBuilder builder = new StringBuilder();
            builder.append(" DateChar between '" + strDate1 + "' and '" + strDate2 + "' ");
            dataBySelect.setParam(builder.toString());
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("advCode", DbConfig.advCode);
            map.put("method", "zhishu");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"CityName,Longitude,Latitude,DateChar,TimeChar,gm,GMGrade,GMText"
                    + ",fy,FYGrade,FYText,shx,SHXGrade,SHXText,xhx,XHXGrade,XHXText,xc,XCGrade,XCText,nyx,NYXGrade,NYXText"
                    + ",ngs,NGSGrade,NGSText,gxb,GXBGrade,GXBText,xjgs,XJGSGrade,XJGSText,gxy,GXYGrade,GXYText,mb,MBGrade,MBText "
                    + ",zz,ZZGrade,ZZText,ls,LSGrade,LSText,ly,LYGrade,LYText,rd,RDGrade,RDText,ss,SSGrade,SSText,pj,PJGrade,PJText"
                    + ",tg,TGGrade,TGText,wr,WRGrade,WRText,zs,ZSGrade,ZSText,cl,CLGrade,CLText,lyou,LYOUGrade,LYOUText,yd,YDGrade,YDText"});
            map = new HashMap<String, String>();
            builder = new StringBuilder();
            dataBySelect.setParam(" DateChar between '" + strDate1 + "' and '" + strDate2 + "' ");
            if (!StringUtil.IsNullOrEmpty(strCityNames)) {
                strCityNames = strCityNames.replace(",", "','");
                builder.append("CityName in ('" + strCityNames + "')");
            }
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("advCode", DbConfig.advCode);
            map.put("method", "zhishu");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            List<zhishu> list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<zhishu>>() {
            });
            result = "[";
//            for (zhishu rs : list) {
//                ResultSetMetaData rsmd = rs.getMetaData();
//                String result1 = "[";
//                for (int i = 5; i < list.size(); i += 3) {
//                    result1 += "{";
//                    result1 += "\"name\":\"" + rs.getString(i) + "\",";
//                    result1 += "\"level\":\"" + rs.getString(i + 1) + "\",";
//
//                    if (rs.getString(i + 1).equals("NULL") || rs.getString(i + 1).length() <= 0) {
//                        result1 += "\"level\":\"" + "无" + "\",";
//                    }
//                    result1 += "\"Text\":\"" + rs.getString(i + 2) + "\",";
//                    if (rs.getString(i + 2) == null) {
//                        result1 += "\"Text\":\"" + "" + "\"";
//                    }
//                    result1 += "},";
//                }
//                result1 = result.substring(0, result.length() - 1) + "]";
//                result += "{";
//                result += "\"cityName\":\"" + rs.getString("cityName") + "\",";
//                result += "\"zhiShuInfo\":\"" + result1 + "\",";
//                result += "\"date\":\"" + rs.getString("DateChar") + "\",";
//                result += "\"sc\":\"" + rs.getString("TimeChar") + "\",";
//
//                result += "\"longitude\":\"" + rs.getDouble("Longitude") + "\",";
//                result += "\"latitude\":\"" + rs.getDouble("Latitude") + "\"";
//                result += "},";
//            }
            result = result.substring(0, result.length() - 1) + "]";
            result = result.replace("\\", "").replace("\"[", "[").replace("]\"", "]");

        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitWaterLoggingMaxTime() {
        // TODO 城市内涝最新时间

        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"forecasttime"});
            dataBySelect.setSort(new String[]{"order by forecasttime desc"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "waterlogging_fcst");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getWaterLogging(HttpServletRequest request) {
        // TODO Auto-generated method stub
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id, forecasttime as 时间,warnarea 淹没区域,warnpos 淹没区坐标,docpath 产品路径"});
            dataBySelect.setParam("forecasttime between '" + strDate1 + "' and '" + strDate2 + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "waterlogging_fcst");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getNeiLaoForecast(HttpServletRequest request) {
        // TODO 城市内涝信息查询
        try {
            String id = request.getParameter("id");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id, forecasttime as 时间,warnarea 淹没区域,warnpos 淹没区坐标,docpath 产品路径"});
            dataBySelect.setParam("id='" + id + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "waterlogging_fcst");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String loadThunderCounty() {
        // TODO 雷电气象--加载县信息
        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"county"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "raidentemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String InitThunderMaxTime() {
        // TODO Auto-generated method stub

        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"observetime"});
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setSort(new String[]{"order by observetime desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "raidentemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getThunder(HttpServletRequest request) {
        // TODO Auto-generated method stub
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strCounty = request.getParameter("county");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(" observetime between '" + strDate1 + "' and '" + strDate2);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "raidentemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(" observetime between '" + strDate1 + "' and '" + strDate2);
            map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "raidentemp");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            List<raidentemp> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<raidentemp>>() {
            });
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (raidentemp rs : listData1) {
                    result += "{";
                    result += "\"strID\":\"" + rs.getId() + "\",";
                    result += "\"dTime\":\"" + rs.getObservetime() + "\",";
                    result += "\"dStrong\":\"" + rs.getStrength() + "\",";
                    result += "\"dDou\":\"" + rs.getSteepness() + "\",";
                    result += "\"dError\":\"" + rs.getError() + "\",";
                    result += "\"city\":\"" + rs.getCity() + "\",";
                    result += "\"county\":\"" + rs.getCounty() + "\",";
                    result += "\"longitude\":\"" + rs.getLon() + "\",";
                    result += "\"latitude\":\"" + rs.getLat() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getArticleType(HttpServletRequest request) {
        // TODO 文章类别
        try {
            String parentId = request.getParameter("parentId");// 大类别

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setSort(new String[]{"order by sortid"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "article_type");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }


            dataBySelect = new RequestDataBySelect();
            map = new HashMap<String, String>();
            dataBySelect.setSort(new String[]{"order by sortid"});
            if (!StringUtil.IsNullOrEmpty(parentId)) {
                dataBySelect.setParam("parentId = '" + parentId + "'");
            }
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "article_type");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            List<ArticleType> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<ArticleType>>() {
            });
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (ArticleType rs : listData1) {
                    result += "{";
                    result += "\"id\":\"" + rs.getId() + "\",";
                    result += "\"typename\":\"" + rs.getTypename() + "\",";
                    result += "\"parentId\":\"" + rs.getParentid() + "\",";
                    result += "\"sortId\":\"" + rs.getSortid() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getWenDang(HttpServletRequest request) {
        // TODO 农气新闻
        // ????????????????
        try {
            String topCount = request.getParameter("topCount");//
            String bigType = request.getParameter("bigType");// 大类别
            String smallType = request.getParameter("smallType");// 小类别
            if (StringUtil.IsNullOrEmpty(topCount)) {
                topCount = "";
            } else {
                topCount = "top " + topCount;
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{" id,title,content,smalltype,bigtype,datamodifydate,uploadtime,publisher,"
                    + "picpath,owner,(case when ishuandeng=1 then '是' else '否' end) as ishuandeng ,click,keyword,miaoshu "});
            dataBySelect.setSort(new String[]{"datamodifydate desc"});
            map.put("method", "addwendang");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            String message = pc.processRequest(map);
            List<Addwendang> listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Addwendang>>() {
            });

            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (Addwendang rs : listData1) {
                    result += "{";
                    result += "\"id\":\"" + rs.getId() + "\",";
                    result += "\"title\":\"" + rs.getTitle() + "\",";
                    result += "\"content\":\"" + rs.getContent() + "\",";
                    result += "\"bigType\":\"" + rs.getBigtype() + "\",";
                    result += "\"smallType\":\"" + rs.getSmalltype() + "\",";
                    result += "\"publisher\":\"" + rs.getPublisher() + "\",";
                    result += "\"owner\":\"" + rs.getOwner() + "\",";
                    result += "\"imgPath\":\"" + rs.getPicpath() + "\",";
                    result += "\"isHuanDeng\":\"" + rs.getIshuandeng() + "\",";
                    result += "\"editDate\":\"" + rs.getDatamodifydate() + "\",";
                    result += "\"uploadDate\":\"" + rs.getUploadtime() + "\",";
                    result += "\"click\":\"" + rs.getClick() + "\",";
                    result += "\"keyword\":\"" + rs.getKeyword() + "\",";
                    result += "\"miaoshu\":\"" + rs.getMiaoshu() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getCropGrowth() {
        // TODO 作物发育期指标
        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_growdate_indexlib");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getDiseasesAndPests() {
        // TODO 病虫害指标
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_dist_index");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            String message = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getWeatherDiseases() {
        // TODO 作物气象灾害指标
        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_weather_dist_indexlib");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            String message = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<CropWeatherDistIndexlib> listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropWeatherDistIndexlib>>() {
            });

            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (CropWeatherDistIndexlib rs : listData1) {
                    result += "{";
                    result += "\"id\":\"" + rs.getId() + "\",";
                    result += "\"cropName\":\"" + rs.getCropname() + "\",";
                    result += "\"growth\":\"" + rs.getGrowthdate() + "\",";
                    result += "\"disStartDate\":\"" + rs.getDisastarttime() + "\",";
                    result += "\"disEndDate\":\"" + rs.getDisaendtime() + "\",";
                    result += "\"incidDisType\":\"" + rs.getEasyhappentype() + "\",";
                    result += "\"disIncidCondition\":\"" + rs.getDisaeasyhappencondition() + "\",";
                    result += "\"defence\":\"" + rs.getDefendmeasure() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String InitHumidMaxTime() {
        // TODO 农气预报--土壤墒情最新时间

        try {

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"observetime"});
            dataBySelect.setSort(new String[]{"order by observetime desc "});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "soil_humidity");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String LoadVideo(HttpServletRequest request) {
        // TODO 农气预报--视频信息
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "video");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<Video> vlist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<Video>>() {});
            if (vlist.size() > 0) {
                result = "[";
                for (Video v : vlist) {
                    String serviceFilePath = "";
                    // 下载
                    String fileName = v.getVideopath();
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path + "/Temp/Video/";
                    String serviceUrl = basePath + fileName;
                    String urlPath;
                    if(operatingSystem.equals("Windows")) {
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Video\\";
                    }else{
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Video/";
                    }
                    serviceFilePath = urlPath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("id", v.getId());
                        queryMap.put("table_name", "video");
                        queryMap.put("advCode", DbConfig.advCode);
                        queryMap.put("collectionName", "video_file");
                        byte[] data = ms.selectData(queryMap);
                        if (data == null) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }

                    String videoPath = serviceFilePath;
                    //添加视频路径
                    result += "{";
                    result += "\"id\":\"" + v.getId().trim() + "\",";
                    result += "\"bigType\":\"" + v.getBigtype().trim() + "\",";
                    result += "\"smallType\":\"" + v.getSmalltype().trim() + "\",";
                    result += "\"title\":\"" + v.getTitle().trim() + "\",";
                    result += "\"publisher\":\"" + v.getPublisher().trim() + "\",";
                    result += "\"videoName\":\"" + v.getVideoname().trim() + "\",";
                    result += "\"videoPath\":\"" + videoPath + "\",";
                    result += "\"editDate\":\"" + new DateTime(v.getDatamodifydate()).toDateString() + "\",";
                    result += "\"lastEditDate\":\"" + v.getFinalmodifydate().toString().trim() + "\",";
                    result += "\"owner\":\"" + v.getOwner().trim() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String LoadAgriStation() {
        // TODO 农服站点信息
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "station_info");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<station_info> slist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<station_info>>() {
            });
            if (slist.size() > 0) {
                result = "[";
                for (station_info s : slist) {
                    result += "{";
                    result += "\"stationID\":\"" + s.getStationid() + "\",";
                    result += "\"stationName\":\"" + s.getStationname() + "\",";
                    result += "\"stationType\":\"" + s.getStationtype() + "\",";
                    result += "\"userType\":\"" + s.getType() + "\",";
                    result += "\"city\":\"" + s.getCity() + "\",";
                    result += "\"county\":\"" + s.getCounty() + "\",";
                    result += "\"town\":\"" + s.getTownship() + "\",";
                    result += "\"village\":\"" + s.getVillage() + "\",";
                    result += "\"ybRelationStaName\":\"" + s.getForecaststationjoin() + "\",";
                    result += "\"ybRelationStaId\":\"" + s.getForecaststationid() + "\",";
                    result += "\"skRelationStaName\":\"" + s.getSmallscalestationjoin() + "\",";
                    result += "\"skRelationStaId\":\"" + s.getSmallscalestationid() + "\",";
                    result += "\"soilRelationSta\":\"" + s.getSoilstationid() + "\",";
                    result += "\"basicSituation\":\"" + s.getBasicsituation() + "\",";
                    result += "\"mianCrop\":\"" + s.getMaincrop() + "\",";
                    result += "\"mianCropGrowthPro\":\"" + s.getMaincroprepweaserproducts() + "\",";
                    result += "\"mianCropYear\":\"" + s.getMaincropanni() + "\",";
                    result += "\"element\":\"" + s.getFarmmonitorelement() + "\",";
                    result += "\"publicType\":\"" + s.getFarminfopubway() + "\",";
                    result += "\"MsgPer\":\"" + s.getInfoofficer() + "\",";
                    result += "\"contactWay1\":\"" + s.getContact1() + "\",";
                    result += "\"contactWay2\":\"" + s.getContact2() + "\",";
                    result += "\"contactWay3\":\"" + s.getContact3() + "\",";
                    result += "\"altitude\":\"" + s.getAlti() + "\",";
                    result += "\"longitude\":\"" + s.getLon() + "\",";
                    result += "\"latitude\":\"" + s.getLat() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getDaHuTongJi(HttpServletRequest request) {
        // TODO 大户统计

        try {
            String strType = request.getParameter("type");


            if (strType.equals("区县")) {
                RequestDataBySelect dataBySelect = new RequestDataBySelect();
                Map<String, String> map = new HashMap<String, String>();
                dataBySelect.setColumns(new String[]{"count(*) as num ,county as type"});
                map.put("method", "station_info");
                map.put("sqlType", "select");
                map.put("advCode", DbConfig.advCode);
                map.put("param", JsonUtil.object2Json(dataBySelect));
                map.put("advCode", DbConfig.advCode);
                String message = pc.processRequest(map);
                List<station_info> listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
                });
                for (station_info rs : listData1) {
                    result += "{";
                    result += "\"num\":\"" + rs.getNum() + "\",";
                    result += "\"type\":\"" + rs.getType() + "\"";
                    result += "},";
                }
                if (listData1.size() < 0) {
                    result = "[]";
                } else {
                    result = result.substring(0, result.length() - 1) + "]";
                }

            } else {
                RequestDataBySelect dataBySelect = new RequestDataBySelect();
                Map<String, String> map = new HashMap<String, String>();
                dataBySelect.setColumns(new String[]{"count(*) as num ,maincrop as type"});
                map.put("method", "station_info");
                map.put("sqlType", "select");
                map.put("advCode", DbConfig.advCode);
                map.put("param", JsonUtil.object2Json(dataBySelect));
                map.put("advCode", DbConfig.advCode);
                String message = pc.processRequest(map);
                List<station_info> listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
                });
//                for (station_info rs : listData1) {
//                    if (rs.getType()+"".equals("甘蔗") || rs.getString("type").equals("香蕉")) {
//                        rs.updateInt(rs.getInt("num"), rs.getInt("num") + 1);
//                    }
//                }
                if (listData1.size() < 0) {
                    result = "[]";
                } else {
                    result = result.substring(0, result.length() - 1) + "]";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getCropName(HttpServletRequest request) {
        // TODO 发育期-农作物名称
        try {
            String strStationId = request.getParameter("staId");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"distinct cropname"});
            dataBySelect.setParam("stationid='" + strStationId + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_growdate_history");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<CropGrowdateHistory> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<CropGrowdateHistory>>() {
            });
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (CropGrowdateHistory rs : listData1) {
                    result += "{\"cropName\":\"" + rs.getCropname() + "\"},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getCropVariety(HttpServletRequest request) {
        // TODO 发育期-农作物品种
        try {
            String strCropName = request.getParameter("cropName");
            String strStationId = request.getParameter("staId");

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"type"});
            dataBySelect.setParam("cropname='" + strCropName + "' and stationid='" + strStationId + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_growdate_history");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            String message = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<CropGrowdateHistory> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<CropGrowdateHistory>>() {
            });
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (CropGrowdateHistory rs : listData1) {
                    result += "{\"cropVariety\":\"" + rs.getType() + "\"},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getGrowthHistory(HttpServletRequest request) {
        // TODO 发育期历史数据
        // 11111111111111111111111
        try {
            String strStationId = request.getParameter("staId");// 站号
            String strCropName = request.getParameter("cropName");// 作物名称
            String strCropVariety = request.getParameter("cropVariety");// 作物品种
            String strYear = request.getParameter("year");// 年份
            String strGrowthName = request.getParameter("growthName");// 发育期名称

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            int whereCount = 0;
            StringBuilder builder = new StringBuilder();
            if (!StringUtil.IsNullOrEmpty(strStationId)) {
                builder.append("stationid='" + strStationId + "'");
                whereCount++;
            }
            if (!StringUtil.IsNullOrEmpty(strCropName)) {
                builder.append(" and cropname='" + strCropName + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strCropVariety)) {
                builder.append(" and type='" + strCropVariety + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strYear)) {
                builder.append(" and year='" + strYear + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strGrowthName)) {
                builder.append(" and growdatename='" + strGrowthName + "'");
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(builder.toString())) {
                builder = builder.replace(0, 4, "");
            }
            dataBySelect.setParam(builder.toString());
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_growdate_history");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            List<CropGrowdateHistory> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<CropGrowdateHistory>>() {
            });
            if (result.equals("")) {
                result = "[]";
            }
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (CropGrowdateHistory rs : listData1) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid().trim() + "\",";
                    result += "\"cropName\":\"" + rs.getCropname().trim() + "\",";
                    result += "\"cropVariety\":\"" + rs.getType().trim() + "\",";
                    result += "\"year\":\"" + rs.getYear() + "\",";
                    result += "\"growthName\":\"" + rs.getGrowdatename().trim() + "\",";
                    result += "\"growthDate\":\"" + rs.getGrowdatedate() + "\",";
                    result += "\"userName\":\"" + rs.getUsername().trim() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getGrowthForcast(HttpServletRequest request) {
        // TODO 发育期预报数据
        try {
            String strStationId = request.getParameter("staId");// 站号
            String strCropName = request.getParameter("cropName");// 作物名称
            String strCropVariety = request.getParameter("cropVariety");// 作物品种
            String strYear = request.getParameter("year");// 年份
            String strGrowthName = request.getParameter("growthName");// 发育期名称

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            int whereCount = 0;
            StringBuilder builder = new StringBuilder();
            if (!StringUtil.IsNullOrEmpty(strStationId)) {
                builder.append("stationid='" + strStationId + "'");
                whereCount++;
            }
            if (!StringUtil.IsNullOrEmpty(strCropName)) {
                builder.append(" and cropname='" + strCropName + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strCropVariety)) {
                builder.append(" and type='" + strCropVariety + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strYear)) {
                builder.append(" and year='" + strYear + "'");
            }
            if (!StringUtil.IsNullOrEmpty(strGrowthName)) {
                builder.append(" and growdatename='" + strGrowthName + "'");
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(builder.toString())) {
                builder = builder.replace(0, 4, "");
            }
            dataBySelect.setParam(builder.toString());
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_growdate_fcst");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            List<CropGrowdateHistory> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<CropGrowdateHistory>>() {
            });
            if (result.equals("")) {
                result = "[]";
            }
            if (listData1 != null && listData1.size() > 0) {
                result = "[";
                for (CropGrowdateHistory rs : listData1) {
                    result += "{";
                    result += "\"stationID\":\"" + rs.getStationid() + "\",";
                    result += "\"cropName\":\"" + rs.getCropname() + "\",";
                    result += "\"cropVariety\":\"" + rs.getType() + "\",";
                    result += "\"year\":\"" + rs.getYear() + "\",";
                    result += "\"growthName\":\"" + rs.getGrowdatename() + "\",";
                    result += "\"growthYbDate\":\"" + rs.getGrowdatedate() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getCropNameInYield(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 产量-农作物名称
        try {
            String strStationId = request.getParameter("staId");//

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"cropname"});
            dataBySelect.setParam("stationid='" + strStationId + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "cropyield_history");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<CropyieldHistory> listData1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<CropyieldHistory>>() {
            });

            // 执行查询
            if (listData1 != null) {
                result = "[";
                for (CropyieldHistory rs : listData1) {
                    result += "{\"cropName\":\"" + rs.getCropname().trim() + "\"},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getCropVarietyInYield(String url, String usr, String psd,
                                        HttpServletRequest request) {
        // TODO 产量-农作物品种
        try {
            String strCropName = request.getParameter("cropName");//
            String strStationId = request.getParameter("staId");//

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"type"});
            dataBySelect.setParam("cropname='" + strCropName + "' and stationid='" + strStationId + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "cropyield_history");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (

                Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getDisImg(HttpServletRequest request) {
        String serviceFilePath = "";
        // 下载
        String fileName = "灾害";
        String path = request.getContextPath();
        String basePath = DbConfig.IP + path
                + "/Temp/Png/";
        String serviceUrl = basePath + fileName;
        String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Png\\";
        serviceFilePath = urlpath + fileName;// 服务器文件
        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
        // 如果目录中不存在文件，下载雷达文件到temp目录
        File serviceFile = new File(serviceFilePath);// 服务器文件
        if (!serviceFile.exists()) {// 把文件上传到服务器
            Map<String, Object> queryMap = new HashMap<String, Object>();
            queryMap.put("type", "干旱");
            queryMap.put("collectionName", "disweather_png_file");
            byte[] data = ms.selectData(queryMap);
            if (data == null) {
                serviceFilePath = "";
            } else {
                FileUtil.bytesToFile(data, serviceFilePath);
            }
        }
        if (!serviceFilePath.equals("")) {
            serviceFilePath = serviceUrl;
        }
        String weburl = serviceFilePath;
        result = "[{";
        result += "\"productname\":\"" + "灾害" + "\",";
        result += "\"url\":\"" + weburl + "\"}]";
        return result;
    }


    @Override
    public String getDisProduct(HttpServletRequest request) {

        String smallType = request.getParameter("smallType");
        // TODO Auto-generated method stub
        String paths = "";
        String bigType = "";
        String param = "";
        result = "[";
        if (smallType.equals("灾害")) {
            result += "{\"producttype\":\"" + "灾害预报" + "\",";
            result += "\"productname\":\"" + "灾害" + "\",";
            bigType = "灾害预报";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "灾害";
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .PNG
        }
        if (smallType.equals("干旱")) {
            result += "{\"producttype\":\"" + "干旱监测与评估产品" + "\",";
            result += "\"productname\":\"" + "干旱" + "\",";
            bigType = "干旱监测与评估产品";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "干旱";
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .PNG
        }
        if (smallType.equals("洪涝")) {
            result += "{\"producttype\":\"" + "暴雨监测与评估产品" + "\",";
            result += "\"productname\":\"" + "洪涝" + "\",";
            bigType = "暴雨监测与评估产品";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "洪涝";
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .PNG
        }
        if (smallType.equals("霜冻")) {
            result += "{\"producttype\":\"" + "霜冻监测与评估产品" + "\",";
            result += "\"productname\":\"" + "霜冻" + "\",";
            bigType = "霜冻监测与评估产品";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "霜冻";
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }
        result = result + "]";
        return result;
    }


    public String getImageId(String producttype, String productname) {
        String result = "";
        String param = "";
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id"});
            dataBySelect.setParam(
                    String.format(" producttype like '%s' and productname like '%%%s%%'", producttype, productname));
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setLimit(1);
            dataBySelect.setSort(new String[]{" maketime desc"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "agri_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);

            if (result.equals("[]")) {
                param = "[]";
            } else {
                String str = result.split(":")[1];
                param = str.substring(0, str.indexOf("}"));
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return param;
    }

    //查24时环保数据
    @Override
    public String getDayProtection(HttpServletRequest request) {
        // TODO 环保实况查询
        try {
            String starttime = request.getParameter("starttime");
            String endtime = request.getParameter("endtime");
            String pollution = request.getParameter("pulltion");
            starttime = starttime + ":00:00";
            endtime = endtime + ":59:59";
            String stationname = "全市平均";

            if (pollution == null && pollution.equals("")) {
                return "[]";
            }
            RequestDataBySelect dbs = new RequestDataBySelect();
            dbs.setParam("stationname='" + stationname + "' and observtime >='" + starttime + "' and observtime <= '" + endtime + "'");
            dbs.setSort(new String[]{"observtime asc"});
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("method", "airpollution");
            mp.put("param", JsonUtil.object2Json(dbs));
            mp.put("advCode", DbConfig.advCode);
            mp.put("sqlType", "select");
            String message = pc.processRequest(mp);
            if (message.equals("")) {
                result = "[]";
            }
            List<airpollution> lis = new ArrayList<airpollution>();
            lis = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<airpollution>>() {
            });

            if (lis.size() > 0) {
                result = "[";
                result += "[";
                for (airpollution a : lis) {

                    Date date = a.getObservtime();
                    String fmobt = new SimpleDateFormat("MM-dd HH").format(date);

                    result += "\"" + fmobt + "\",";
                }
                result = result.substring(0, result.length() - 1) + "],[";
                for (airpollution a : lis) {
                    if (pollution.equals("PM2.5")) {
                        result += "\"" + a.getConcenpm2p5() + "\",";
                    } else if (pollution.equals("PM10")) {
                        result += "\"" + a.getConcenpm10() + "\",";
                    } else if (pollution.equals("AQI")) {
                        result += "\"" + a.getAqi() + "\",";
                    } else if (pollution.equals("SO2")) {
                        result += "\"" + a.getConcenso2() + "\",";
                    } else if (pollution.equals("CO2")) {
                        result += "\"" + a.getConcenno2() + "\",";
                    } else if (pollution.equals("CO")) {
                        result += "\"" + a.getConcenco() + "\",";
                    } else if (pollution.equals("O3")) {
                        result += "\"" + a.getConceno3() + "\",";
                    }
                }

                result = result.substring(0, result.length() - 1) + "]]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getrainWeather(HttpServletRequest request) {
        String type = request.getParameter("type");
        String county = request.getParameter("county");
        try {
            Date date = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.HOUR, -Integer.parseInt(type) + 1);
            Date star = calendar.getTime();
            String fmobt = new SimpleDateFormat("yyyy-MM-dd HH").format(date) + "  数据";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
            String starttime = sdf.format(star) + ":00:00";
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            columns.add("StationName");
            columns.add("StationId");
            columns.add("sum(rain) as rain");
            dataBySelect.setSort(new String[]{"rain desc"});
            dataBySelect
                    .setParam(String.format(" observtime>='%s' and county like  '%s%%'  and 1=1", starttime, county));//
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            Map<String, String> map = new HashMap<String, String>();
            map.put("method", "msgmediumsmallscale");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<msgmediumsmallscale> list = new ArrayList<msgmediumsmallscale>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<msgmediumsmallscale>>() {
            });
            String staname;
            int aqi;
            if (list.size() > 0) {
                result = "[";
                for (msgmediumsmallscale ai : list) {
                    result += "{";
                    result += "\"stationname\":\"" + ai.getStationname().trim() + "\",";
                    result += "\"observtime\":\"" + fmobt + "\",";
                    result += "\"rain\":\"" + ai.getRain() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
            result = result.substring(0, result.length() - 1) + "]";

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getrainCondition(String url, String usr, String psd, HttpServletRequest request) {
        String county = request.getParameter("county");
        String city = "";
        if (county == "") {
            city = DbConfig.CITY;
        }
        String starttime = request.getParameter("startTime") + ":00:00";
        String endtime = request.getParameter("endTime") + ":00:00";
        String pos = request.getParameter("pos");
        DmMapRectangle rect = new DmMapRectangle();
        if (!pos.equals("all")) {
            String villagenames = "";

            String[] dotset = pos.split(";");// 坐标数组
            DmMapPoint[] points = new DmMapPoint[dotset.length];
            Integer index = 0;
            for (String strDot : dotset) {
                String[] dot = strDot.split(",");
                DmMapPoint dmDot = new DmMapPoint(Double.parseDouble(dot[0]), Double.parseDouble(dot[1]));
                points[index] = dmDot;
                index++;
            }
            MapCommon dmMapCom = new MapCommon();
            int[] parts = new int[1];
            parts[0] = points.length;
            rect = dmMapCom.getObjRect(Arrays.asList(points));
        }
        try {
            Map<String, String> Stamap = new HashMap<String, String>();   //雨量站点映射表
            //初始化雨量站点信息
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            Map<String, String> map = new HashMap<String, String>();
            columns.add("stcd");
            columns.add("stnm");
            columns.add("lgtd");
            columns.add("lttd");
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            map = new HashMap<String, String>();
            map.put("method", "water_station");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            List<water_station> rainStalist = new ArrayList<water_station>();
            rainStalist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water_station>>() {
            });
            if (rainStalist.size() > 0) {
                for (int i = 0; i < rainStalist.size(); i++) {
                    Stamap.put(rainStalist.get(i).getStcd(), rainStalist.get(i).getStnm() + ";" + rainStalist.get(i).getLgtd() + ";" + rainStalist.get(i).getLttd());
                }
            }
            dataBySelect = new RequestDataBySelect();
            columns = new ArrayList<String>();
            columns.add("StationName");
            columns.add("StationId");
            columns.add("longitude");
            columns.add("latitude");
            columns.add("sum(rain) as rain");
            dataBySelect.setSort(new String[]{"rain desc"});
            if (pos.equals("all")) {
                dataBySelect.setParam(String.format(" observtime>='%s' and observtime<='%s' and stationname like  '%s%%'   and city like  '%s%%'",
                        starttime, endtime, city, county));//
            } else {
                if (rect == null) {
                    return "[]";
                }
                dataBySelect.setParam(String.format(" observtime>='%s' and observtime<='%s'   and city like  '%s%%' " +
                                " and longitude>='%s' and longitude<='%s' and  latitude>='%s' and  latitude<='%s'",
                        starttime, endtime, county, rect.minX, rect.maxX, rect.minY, rect.maxY));//
            }
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            map = new HashMap<String, String>();
            map.put("method", "msgmediumsmallscale");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<msgmediumsmallscale> list = new ArrayList<msgmediumsmallscale>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<msgmediumsmallscale>>() {
            });

            //查询雨量站的实况信息
            dataBySelect = new RequestDataBySelect();
            columns = new ArrayList<String>();
            columns.add("stcd");
            columns.add("sum(drp) as drp");
            dataBySelect.setSort(new String[]{"drp desc"});
            if (pos.equals("all")) {
                dataBySelect.setParam(String.format(" tm>='%s' and tm<='%s'",
                        starttime, endtime));
            } else {
                if (rect == null) {
                    return "[]";
                }
            }
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            map = new HashMap<String, String>();
            map.put("method", "water_rain");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<water_rain> rainlist = new ArrayList<water_rain>();
            rainlist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water_rain>>() {
            });

            //获取区域站最大降雨量 站点
            msgmediumsmallscale msg = new msgmediumsmallscale();
            if (list.size() > 0 && list.get(0).getRain() != null) {
                Stream<msgmediumsmallscale> stream = list.stream();
                msgmediumsmallscale max = stream.max((s1, s2) -> {         //匿名比较器
                    double d1 = Double.parseDouble(s1.getRain().toString());
                    double d2 = Double.parseDouble(s2.getRain().toString());
                    if (d1 > d2) {
                        return 1;
                    } else if (d1 < d2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }).get();
                String station = max.getStationname();
                //构建查询查找这个station 的最大小时雨强
                msg = getMaxRain(station, starttime, endtime, county);
            }
            //获取雨量站最大降雨量站点
            water_rain rainmsg = new water_rain();
            if (rainlist.size() > 0 && rainlist.get(0).getDrp() != null) {
                Stream<water_rain> rainstream = rainlist.stream();
                water_rain rainmax = rainstream.max((s1, s2) -> {         //匿名比较器
                    double d1 = Double.parseDouble(s1.getDrp().toString());
                    double d2 = Double.parseDouble(s2.getDrp().toString());
                    if (d1 > d2) {
                        return 1;
                    } else if (d1 < d2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }).get();
                String rainstation = rainmax.getStcd();
                //构建查询查找这个station 的最大小时雨强
                rainmsg = getRainMaxRain(rainstation, starttime, endtime);
            }
            //构建返回提
            result = "[";
            result += "[";

            if (list.size() > 0) {
                for (msgmediumsmallscale ai : list) {
                    result += "{";
                    result += "\"stationname\":\"" + ai.getStationname().trim() + "\",";
                    result += "\"rain\":\"" + ai.getRain() + "\",";
                    result += "\"lon\":\"" + ai.getLongitude() + "\",";
                    result += "\"lat\":\"" + ai.getLatitude() + "\",";
                    if (ai.getStationid().equals(msg.getStationid())) {  //最大小时雨强
                        result += "\"maxrain\":\"" + msg.getMaxtemp() + "\"";
                    } else {
                        result += "\"maxrain\":\"" + "\"";
                    }
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result += "]";
            }
            result += ",[";
            boolean isData = false;   //记录是否添加了数据
            if (rainlist.size() > 0) {
                for (water_rain ai : rainlist) {
                    if (ai.getDrp() == null || ai.getStcd() == null || Stamap.get(ai.getStcd().trim()) == null)
                        continue;
                    result += "{";
                    result += "\"stationname\":\"" + Stamap.get(ai.getStcd().trim()).split(";")[0] + "\",";
                    result += "\"rain\":\"" + ai.getDrp() + "\",";
                    result += "\"lon\":\"" + Stamap.get(ai.getStcd().trim()).split(";")[1] + "\",";
                    result += "\"lat\":\"" + Stamap.get(ai.getStcd().trim()).split(";")[2] + "\",";
                    if (rainmsg.getStcd() != null) {  //最大小时雨强
                        if (ai.getStcd().equals(rainmsg.getStcd()) && rainmsg.getDrp() != null) {
                            result += "\"maxrain\":\"" + rainmsg.getDrp() + "\"";
                        } else {
                            result += "\"maxrain\":\"" + "\"";
                        }
                    } else {
                        result += "\"maxrain\":\"" + "\"";
                    }
                    result += "},";
                    isData = true;
                }
                if (isData)
                    result = result.substring(0, result.length() - 1) + "]";
                else
                    result += "]";
            } else {
                result += "]";
            }
            result += "]";


        } catch (Exception e) {
            e.printStackTrace();
            result = result.substring(0, result.length() - 1) + "]";
            result += ",[]]";

        }
        System.out.println(result + "返回结果");
        return result;

    }


    public water_rain getRainMaxRain(String station, String starttime, String endtime) {
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();

            List<String> columns = new ArrayList<String>();
            columns.add("stcd");
            columns.add("max(drp)  as  drp ");

            dataBySelect.setParam(String.format(" tm>='%s' and tm<='%s' and stcd like  '%s%%'", starttime, endtime, station));//
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));

            Map<String, String> map = new HashMap<String, String>();
            map.put("method", "water_rain");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<water_rain> list = new ArrayList<water_rain>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water_rain>>() {
            });

            if (list.size() != 1) {
                return null;
            } else {
                return list.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    public msgmediumsmallscale getMaxRain(String station, String starttime, String endtime, String county) {
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();

            List<String> columns = new ArrayList<String>();
            columns.add("StationName");
            columns.add("StationId");
            columns.add("max(rain)  as  maxtemp ");

            dataBySelect.setParam(String.format(" observtime>='%s' and observtime<='%s' and stationname = '%s'   and city like  '%s%%'", starttime, endtime, station, county));//
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            Map<String, String> map = new HashMap<String, String>();
            map.put("method", "msgmediumsmallscale");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<msgmediumsmallscale> list = new ArrayList<msgmediumsmallscale>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<msgmediumsmallscale>>() {
            });

            if (list.size() < 1) {
                return null;
            } else {
                return list.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public String getqsProtect(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 全市环保实况查询
        try {
            String stationname = request.getParameter("stationname");
            RequestDataBySelect dbs = new RequestDataBySelect();
            dbs.setColumns(new String[]{"observtime"});
            dbs.setSort(new String[]{"observtime desc"});
            dbs.setParam(String.format(" stationname ='%s'", stationname));
            dbs.setLimit(1);
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("method", "airpollution");
            mp.put("advCode", DbConfig.advCode);
            mp.put("param", JsonUtil.object2Json(dbs));
            mp.put("sqlType", "select");
            result = pc.processRequest(mp);
            if (result.equals("")) {
                result = "[]";
            }
            List<airpollution> lis = new ArrayList<airpollution>();
            lis = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<airpollution>>() {
            });
            if (lis.size() > 0) {
                for (airpollution a : lis) {
                    Date date = a.getObservtime();
                    String fmobt = new SimpleDateFormat("yyyy-MM-dd HH").format(date) + "时发布";
                    RequestDataBySelect dataBySelect = new RequestDataBySelect();
                    dataBySelect.setColumns(
                            new String[]{"stationname,aqi,concenpm2p5,concenpm10,firstpollution,pollutionlevel,"
                                    + "concenso2,concenno2,concenco,conceno3"});
                    dataBySelect
                            .setParam("stationname='" + stationname + "' and  observtime='" + a.getObservtime() + "'");
                    dataBySelect.setSort(new String[]{"aqi desc"});
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("method", "airpollution");
                    mp.put("advCode", DbConfig.advCode);
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("sqlType", "select");
                    result = pc.processRequest(map);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<airpollution> list = new ArrayList<airpollution>();
                    list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<airpollution>>() {
                    });
                    String staname;
                    int aqi;
                    if (list.size() > 0) {
                        result = "[";
                        for (airpollution ai : list) {
                            result += "{";
                            result += "\"stationname\":\"" + ai.getStationname().trim() + "\",";
                            result += "\"observtime\":\"" + fmobt + "\",";
                            result += "\"pm2.5\":\"" + ai.getConcenpm2p5() + "\",";
                            result += "\"pm10\":\"" + ai.getConcenpm10() + "\",";
                            result += "\"firstpollution\":\"" + ai.getFirstpollution() + "\",";
                            result += "\"pollutionlevel\":\"" + ai.getPollutionlevel() + "\",";
                            result += "\"so2\":\"" + ai.getConcenso2() + "\",";
                            result += "\"co2\":\"" + ai.getConcenno2() + "\",";
                            result += "\"aqi\":\"" + ai.getAqi() + "\",";
                            result += "\"co\":\"" + ai.getConcenco() + "\",";
                            result += "\"fracto3\":\"" + ai.getConceno3() + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getjdSenlinhx(HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id,context"});
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setParam(String.format("producttype like '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                result = "[";
                for (base_product b : list) {
                    result += "{";
                    String replace = "";
                    if (b.getContext().contains("\r\n")) {
                        replace = b.getContext().replace("\r\n", " ");
                    } else {
                        replace = b.getContext();
                    }
                    result += "\"context\":\"" + replace + "\"";
                    result += "},";
                    result += "{";
                    result += "\"id\":\"" + b.getId() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getjtyj(HttpServletRequest request) {
        int ntimes = 0;
        List<traffic> list1 = new ArrayList<traffic>();
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = sdf.format(nowtime) + " 23:59:59";
            String starttime = sdf.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"forecasttime", "id"});
            dataBySelect.setParam(String.format("producttype like '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
                String forecasttime = simpleDateFormat.format(list.get(0).getForecasttime()) + ":00:00";
                ntimes = getTrafficNtimes(forecasttime);
            }
            if (list.size() > 0) {
                for (base_product b : list) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
                    String forecasttime = simpleDateFormat.format(b.getForecasttime()) + ":00:00";
                    RequestDataBySelect dbs = new RequestDataBySelect();
                    dbs.setColumns(new String[]{"stationname", "forcastlevel", "explain"});
                    dbs.setParam("id desc");
                    dbs.setParam(String.format("announcedtime= '%s'  and ntimes='" + ntimes + "'",
                            forecasttime));//
                    Map<String, String> map1 = new HashMap<String, String>();
                    map1.put("param", JsonUtil.object2Json(dbs));
                    map1.put("method", "traffic");
                    map1.put("advCode", DbConfig.advCode);
                    map1.put("sqlType", "select");
                    result = pc.processRequest(map1);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<traffic>>() {
                    });
                    if (list1.size() > 0) {
                        result = "[";
                        for (traffic h : list1) {
                            String warnrs = h.getStationname();
                            String warn1 = h.getForcastlevel().toString();
                            String warn2 = h.getExplain();
                            warnrs = warnrs + ":<br/>" + forecasttime.split(" ")[0] + "日路况:" + warn1 + "级" + "<br/>"
                                    + warn2;
                            result += "{";
                            result += "\"warnresult\":\"" + warnrs + "\"";
                            result += "},";
                        }
                        result += "{";
                        result += "\"id\":\"" + b.getId() + "\"";
                        result += "},";
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                }
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    public int getTrafficNtimes(String forecasttime) throws IOException {
        List<traffic> list1 = new ArrayList<traffic>();
        int ntimes = 1;
        RequestDataBySelect dbs = new RequestDataBySelect();
        dbs.setColumns(new String[]{"ntimes"});
        dbs.setParam("id desc");
        dbs.setLimit(1);
        dbs.setParam(String.format("announcedtime= '%s'", forecasttime));//
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("param", JsonUtil.object2Json(dbs));
        map1.put("method", "traffic");
        map1.put("advCode", DbConfig.advCode);
        map1.put("sqlType", "select");
        result = pc.processRequest(map1);
        if (result.equals("")) {
            result = "[]";
        }
        list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<traffic>>() {
        });
        if (list1.size() > 0) {
            ntimes = list1.get(0).getNtimes();
        } else {
            return 0;
        }
        return ntimes;
    }

    @Override
    public String getSenlinhx(String url, String zyDbname, String usr, String psd, HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,bindid"});
            dataBySelect.setParam(String.format("producttype like '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                for (base_product b : list) {
                    String bindid = b.getBindid();
                    RequestDataBySelect dbs = new RequestDataBySelect();
                    dbs.setColumns(new String[]{"warn_result"});
                    dbs.setParam(String.format("docid = '%s'", bindid));//
                    Map<String, String> map1 = new HashMap<String, String>();
                    map1.put("param", JsonUtil.object2Json(dbs));
                    map1.put("method", "hxyj_warning");
                    map1.put("advCode", DbConfig.advCode);
                    map1.put("sqlType", "select");
                    result = pc.processRequest(map1);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<hxyj_warning> list1 = new ArrayList<hxyj_warning>();
                    list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<hxyj_warning>>() {
                    });
                    if (list1.size() > 0) {
                        result = "[";
                        for (hxyj_warning h : list1) {
                            String warnrs = h.getWarn_result();
                            String warn1 = warnrs.split("\r\n")[0];
                            String warn2 = warnrs.split("\r\n")[1];
                            warnrs = warn1 + "<br>" + warn2;
                            result += "{";
                            result += "\"warnresult\":\"" + warnrs + "\"";
                            result += "},";
                            result += "{";
                            result += "\"id\":\"" + b.getId() + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                }
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getZhTime(String url, String zyDbname, String usr, String psd, HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();

            dataBySelect.setColumns(new String[]{"id,maketime,forecasttime"});
            dataBySelect.setParam(String.format("producttype like '%s'", producttype));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            SimpleDateFormat simpleDateForma = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            result = "[";
            result += "{";
            result += "\"maketime\":\"" + simpleDateForma.format(list.get(0).getMaketime()) + "\"";
            result += "}]";

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getcontext(HttpServletRequest request) {
        String rsult = "";
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,bindid,context"});
            dataBySelect.setParam(String.format("producttype = '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//starttime
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                for (base_product s : list) {
                    rsult += "[{";
                    String picid = "";
                    picid = s.getContext().trim();
                    rsult += "\"context\":\"" + picid.replaceAll("(\\r\\n|\\n|\\n\\r)", "<br/>") + "\"";
                    rsult += "},";
                    rsult += "{";
                    rsult += "\"id\":\"" + s.getId() + "\"";
                    rsult += "},";
                }
                rsult = rsult.substring(0, rsult.length() - 1) + "]";
            } else {
                rsult += "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            rsult = "[{\"returnState\":\"0\"}]";
        }
        return rsult;
    }


    @Override
    public String getShanhongyj(String url, String usr, String psd, HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,bindid"});
            dataBySelect.setParam(String.format("producttype = '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                for (base_product b : list) {
                    String bindid = b.getBindid();
                    RequestDataBySelect dbs = new RequestDataBySelect();
                    dbs.setColumns(new String[]{"context"});
                    dbs.setParam(String.format("id = '%s'", b.getId()));
                    Map<String, String> map1 = new HashMap<String, String>();
                    map1.put("param", JsonUtil.object2Json(dbs));
                    switch (producttype) {
                        case "山洪防汛预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "地质灾害预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "森林火险预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "潜势预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "铁塔山洪灾害预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "铁塔地质灾害预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                        case "城市内涝预报":
                            map1.put("method", "base_product");
                            map1.put("advCode", DbConfig.advCode);
                            map1.put("sqlType", "select");
                            result = pc.processRequest(map1);
                            break;
                    }

                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<base_product> list1 = new ArrayList<base_product>();
                    list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
                    });
                    if (list1.size() > 0) {
                        result = "[";
                        for (base_product s : list1) {
                            result += "{";
                            String replace = "";
                            replace = s.getContext();
                            result += "\"context\":\"" + replace + "\"";
                            result += "},";
                            result += "{";
                            result += "\"id\":\"" + b.getId() + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                    if (list1.size() > 0) {
                        result = "[";
                        for (base_product s : list1) {
                            result += "{";
                            String replace = "";
                            replace = s.getContext();
                            result += "\"context\":\"" + replace + "\"";
                            result += "},";
                            result += "{";
                            result += "\"id\":\"" + b.getId() + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                }
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getQianshiyubao(HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,bindid,context"});
            dataBySelect.setParam(String.format("producttype like '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                result = "[";
                for (base_product s : list) {
                    result += "{";
                    result += "\"id\":\"" + s.getId() + "\",";
                    result += "\"context\":\"" + s.getContext() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getProductList(String url, String zyDbname, String usr, String psd, HttpServletRequest request) {
        // TODO 产品
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strBigType = request.getParameter("bigType");// 大类别
            String strSmallType = request.getParameter("smallType");// 小类别
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(" maketime between '" + strDate1 + "' and '" + strDate2 + "' and 1=1");
            dataBySelect.setSort(new String[]{"maketime desc"});
            dataBySelect.setLimit(1);
            if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
            }
            Map<String, String> map = new HashMap<String, String>();
            String tableName = "";
            switch (strBigType) {
                case "公共气象": {
                    tableName = "base_product";
                }
                ;
                break;
                case "电力气象": {
                    tableName = "power_product";
                }
                ;
                break;
                case "人保气象": {
                    tableName = "agri_product";
                }
                ;
                break;
                case "农业气象": {
                    tableName = "agri_product";
                }
                ;
                break;
            }
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", tableName);
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("1=1");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                    dataBySelect1
                            .setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
                }
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", tableName);
                map1.put("advCode", DbConfig.advCode);
                map1.put("sqlType", "select");
                result = pc.processRequest(map1);
            }


            String urls = DbConfig.IP
                    + request.getContextPath();
            String weburl = urls + "/download?";

            switch (strBigType) {
                case "公共气象": {
                    List<base_product> forecast = new ArrayList<base_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (base_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    collectionName = "doc_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                // mongodb下载参数
                                String param = "collectionName=" + collectionName + "&id=" + fileId + "&table_name="
                                        + tableName + "&resultType=" + resultType;
                                // + "&productname=" + fileName.substring(0,
                                // fileName.length() - 4);
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + weburl + param + "&advCode=" + DbConfig.advCode + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
                case "电力气象": {
                    List<power_product> forecast = new ArrayList<power_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<power_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (power_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    collectionName = "doc_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                // mongodb下载参数
                                String param = "collectionName=" + collectionName + "&id=" + fileId + "&table_name="
                                        + tableName + "&resultType=" + resultType;
                                // + "&productname=" + fileName.substring(0,
                                // fileName.length() - 4);
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + weburl + param + "&advCode=" + DbConfig.advCode + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }

                }
                break;
                case "人保气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    collectionName = "doc_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                // mongodb下载参数
                                String param = "collectionName=" + collectionName + "&id=" + fileId + "&table_name="
                                        + tableName + "&resultType=" + resultType;
                                // + "&productname=" + fileName.substring(0,
                                // fileName.length() - 4);
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + weburl + param + "&advCode=" + DbConfig.advCode + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
                case "农业气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    collectionName = "doc_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                // mongodb下载参数
                                String param = "collectionName=" + collectionName + "&id=" + fileId + "&table_name="
                                        + tableName + "&resultType=" + resultType;
                                // + "&productname=" + fileName.substring(0,
                                // fileName.length() - 4);
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + weburl + param + "&advCode=" + DbConfig.advCode + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                break;
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
        }
        return result;
    }


    /***
     * 验证是否用户关联
     * @param url
     * @param zyDbname
     * @param usr
     * @param psd
     * @param request
     * @return
     */
    @Override
    public String isGuanlian(String url, String zyDbname, String usr, String psd, HttpServletRequest request) {
        if (request.getSession().getAttribute("openid") != null) {
//			String openid = "oO7uOwDAoysxvRvz3ruKVAzaD0tE";
            String openid = request.getSession().getAttribute("openid").toString();
//			String openid = "oRXVw1QmNcyQ-jcmyKcUWTO4KiRk";
            return getGuanlianInfo(openid, request);
        } else {
            try {
                String code = request.getParameter("code");//编码
                String action = request.getParameter("action");//动作
                String state = request.getParameter("state");//状态1

//				String code="071ujeif1bHGdu01uyif1XAXhf1ujeiJ";
//				String state="1";

                if (code != null && state != null) {//微信授权判断，是否有更好的方式？//&& action != null action不判断
                    String openid = (String) request.getSession().getAttribute("openid");
                    if ("".equals(openid) || openid == null) {
                        //先要判断是否是获取code后跳转过来的
                        if (!StringUtil.IsNullOrEmpty(code)) {
//							openid ="oO7uOwDAoysxvRvz3ruKVAzaD0tE";//重新取得用户的openid
                            openid = WeiXinUtil.GetOauthAccessOpenId(code);//重新取得用户的openid
                            request.getSession().setAttribute("openid", openid);
                        }
                        return getGuanlianInfo(openid, request);
                    }
                }
            } catch (Exception ex) {
                ex.getStackTrace();
            }
        }
        return "[]";
    }

    private String getGuanlianInfo(String openid, HttpServletRequest request) {
        try {
            if (openid != null) {
                RequestDataBySelect dataBySelect = new RequestDataBySelect();
                dataBySelect.setParam(String.format("openid='%s'", openid));
                Map<String, String> map = new HashMap<String, String>();
                dataBySelect.setLimit(1);
                map.put("param", JsonUtil.object2Json(dataBySelect));
                map.put("method", "wxuserblind");
                map.put("advCode", DbConfig.advCode);
                map.put("sqlType", "select");
                String result = pc.processRequest(map);
                if (result.equals("")) {
                    result = "[]";
                }
                List<WeiXinUser> list = new ArrayList<WeiXinUser>();
                list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<WeiXinUser>>() {
                });
                if (list != null && list.size() > 0) {
                    if (!StringUtil.IsNullOrEmpty(list.get(0).getUserName())) {
                        dataBySelect = new RequestDataBySelect();
                        dataBySelect.setParam("username='" + list.get(0).getUserName() + "' and servicewechataddress like '%weixin%'");
                        map = new HashMap<String, String>();
                        dataBySelect.setLimit(1);
                        map.put("param", JsonUtil.object2Json(dataBySelect));
                        map.put("method", "user_table");
                        map.put("advCode", DbConfig.advCode);
                        map.put("sqlType", "select");
                        result = pc.processRequest(map);
                        if (result.equals("")) {
                            result = "[]";
                        }
                        List<user_table> list1 = new ArrayList<user_table>();
                        list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<user_table>>() {
                        });
                        if (list1 != null && list1.size() > 0) {
                            if (list1.get(0).getServicewechataddress().contains("nongyedh_index.jsp") && !list.get(0).getUserName().equals("nyj")) {
                                try {
                                    RequestDataBySelect dhdataBySelect = new RequestDataBySelect();
                                    dhdataBySelect
                                            .setParam(String.format("username='%s'", list.get(0).getUserName()).trim());
                                    Map<String, String> dhmap = new HashMap<String, String>();
                                    dhdataBySelect.setLimit(1);
                                    dhmap.put("param", JsonUtil.object2Json(dhdataBySelect));
                                    dhmap.put("method", "users");
                                    dhmap.put("advCode", DbConfig.advCode);
                                    dhmap.put("sqlType", "select");
                                    String message = pc.processRequest(dhmap);
                                    if (message.equals("")) {
                                        message = "[]";
                                    }
                                    List<users> dhlist = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<users>>() {
                                    });
                                    if (dhlist.size() > 0 && dhlist.get(0).getType().equals("农业大户")) {
                                        request.getSession().setAttribute("userInfo", list1.get(0));
                                        String username = list1.get(0).getUsername();
                                        request.getSession().setAttribute("UserName", username);// 保存了一个user对象进session
                                        return "[{\"address\":\"" + list1.get(0).getServicewechataddress() + "?stationName="
                                                + dhlist.get(0).getOwnertown() + "\"}]";
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else if (list.get(0).getUserName().equals("nyj")) {
                                request.getSession().setAttribute("userInfo", list1.get(0));
                                String username = list1.get(0).getUsername();
                                request.getSession().setAttribute("UserName", username);// 保存了一个user对象进session
                                return "[{\"address\":\"" + list1.get(0).getServicewechataddress() + "?stationName=小渡口镇" + "\"}]";
                            } else {
                                request.getSession().setAttribute("userInfo", list1.get(0));
                                String username = list1.get(0).getUsername();
                                request.getSession().setAttribute("UserName", username);// 保存了一个user对象进session
                                return "[{\"address\":\"" + list1.get(0).getServicewechataddress() + "\",\"reservoirname\":\"" + list1.get(0).getReservoirname() + "\",\"drainagearea\":\"" + list1.get(0).getDrainagearea() + "\",\"reservoirid\":\"" + list1.get(0).getReservoirid() + "\",\"county\":\"" + list1.get(0).getCounty() + "\"  }]";
                            }
                        }
                    } else {
                        //清除session信息，注意，不能清除openid的session
                        request.getSession().removeAttribute("userInfo");
                        return "[]";
                    }
                }
            }
        } catch (Exception ex) {
            ex.getStackTrace();
        }
        return "[]";
    }


    /***
     * 农情监控
     * @param url
     * @param usr
     * @param psd
     * @return
     */
    @Override
    public String LoadAgriMonitorInfo(String url, String usr, String psd) {
        try {
            String strData = DateTime.now().AddHours(-24).toDateTimeString("yyyy-MM-dd HH:mm:ss");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(String.format(" isremove=0  and warningtime>'%s'", strData));
            dataBySelect.setSort(new String[]{"warningtime desc"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "agri_moni_info");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            String message = pc.processRequest(map);
            if (message.equals("")) {
                message = "[]";
            }
            List<agri_moni_info> list = new ArrayList<agri_moni_info>();
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_moni_info>>() {
            });

            if (list.size() > 0) {
                result = "[";
                for (agri_moni_info u : list) {
                    dataBySelect = new RequestDataBySelect();
                    dataBySelect.setParam(String.format(" stationid = '%s'", u.getStationid()));
                    map = new HashMap<String, String>();
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("method", "station_info");
                    map.put("advCode", DbConfig.advCode);
                    map.put("sqlType", "select");
                    message = pc.processRequest(map);
                    if (message.equals("")) {
                        message = "[]";
                    }
                    List<station_info> list1 = new ArrayList<station_info>();
                    list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
                    });
                    if (list1.size() > 0) {
                        for (station_info s : list1) {
                            result += "{";
                            result += "\"stationid\":\"" + u.getStationid() + "\",";
                            result += "\"cropname\":\"" + u.getCropname() + "\",";
                            result += "\"growdatename\":\"" + u.getGrowdatename() + "\",";
                            result += "\"warningtype\":\"" + u.getWarningtype() + "\",";
                            result += "\"warningtime\":\"" + u.getWarningtime() + "\",";
                            result += "\"longitude\":\"" + s.getLon() + "\",";
                            result += "\"latitude\":\"" + s.getLat() + "\",";
                            result += "\"isremove\":\"" + u.getIsremove() + "\"";
                            result += "},";
                        }
                    }
                }
                if (result.endsWith(","))
                    result = result.substring(0, result.length() - 1);
                result += "]";
            } else {
                result = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    /***
     * 农业病虫害监控
     * @param url
     * @param
     * @param usr
     * @param psd
     * @return
     */
    @Override
    public String LoadBchMonitorInfo(String url, String usr, String psd) {
        try {
            String strData = DateTime.now().AddHours(-24).toDateTimeString("yyyy-MM-dd HH:mm:ss");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(String.format(" isremove=0  and warningtime>'%s'", strData));
            dataBySelect.setSort(new String[]{"warningtime desc"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "diseasemonitorinfo");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            String message = pc.processRequest(map);
            if (message.equals("")) {
                message = "[]";
            }
            List<diseasemonitorinfo> list = new ArrayList<diseasemonitorinfo>();
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<diseasemonitorinfo>>() {});

            if (list.size() > 0) {
                result = "[";
                for (diseasemonitorinfo u : list) {
                    dataBySelect = new RequestDataBySelect();
                    dataBySelect.setParam(String.format(" stationid = '%s'", u.getStationid()));
                    map = new HashMap<String, String>();
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("method", "station_info");
                    map.put("advCode", DbConfig.advCode);
                    map.put("sqlType", "select");
                    message = pc.processRequest(map);
                    if (message.equals("")) {
                        message = "[]";
                    }
                    List<station_info> list1 = new ArrayList<station_info>();
                    list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
                    });
                    if (list1.size() > 0) {
                        for (station_info s : list1) {
                            result += "{";
                            result += "\"stationid\":\"" + u.getStationid() + "\",";
                            result += "\"cropname\":\"" + u.getCropname() + "\",";
                            result += "\"diseasesname\":\"" + u.getDiseasesname() + "\",";
                            result += "\"warningtype\":\"" + u.getWarningtype() + "\",";
                            result += "\"warningtime\":\"" + new DateTime(u.getWarningtime()).toDateString() + "\",";
                            result += "\"longitude\":\"" + s.getLon() + "\",";
                            result += "\"latitude\":\"" + s.getLat() + "\",";
                            result += "\"isremove\":\"" + u.getIsremove() + "\"";
                            result += "},";
                        }
                    }
                }
                if (result.endsWith(","))
                    result = result.substring(0, result.length() - 1);
                result += "]";
            } else {
                result = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String UserLogin(String url, String zyDbname, String usr, String psd, HttpServletRequest request) {
        // TODO 用户登录
        try {
            String strUserName = request.getParameter("userName");
            String strPw = request.getParameter("passWord");// 站点编号
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(String.format("username='%s' and password='%s'", strUserName, strPw).trim());
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "user_table");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<user_table> list = new ArrayList<user_table>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<user_table>>() {
            });
            String message = "";
            List<users> dhlist = new ArrayList<users>();
            if (list.get(0).getServicewechataddress().contains("nongyedh_index.jsp") && !strUserName.equals("nyj")) {
                try {
                    String userName = list.get(0).getUsername();
                    String passWord = list.get(0).getPassword();
                    RequestDataBySelect dhdataBySelect = new RequestDataBySelect();
                    dhdataBySelect
                            .setParam(String.format("username='%s' and password='%s'", userName, passWord).trim());
                    Map<String, String> dhmap = new HashMap<String, String>();
                    dhdataBySelect.setLimit(1);
                    dhmap.put("param", JsonUtil.object2Json(dhdataBySelect));
                    dhmap.put("method", "users");
                    map.put("advCode", DbConfig.advCode);
                    dhmap.put("sqlType", "select");
                    message = pc.processRequest(dhmap);
                    if (message.equals("")) {
                        message = "[]";
                    }
                    dhlist = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<users>>() {
                    });
                    if (dhlist.size() > 0 && dhlist.get(0).getType().equals("农业大户")) {
                        result = "[{";
                        for (user_table u : list) {
                            result += "\"webUrl\":\"" + u.getServicewebaddress() + "\",";
                            result += "\"weChat\":\"" + u.getServicewechataddress() + "?stationName="
                                    + dhlist.get(0).getOwnertown() + "\",";
                            result += "\"entryTime\":\"" + u.getInputtime() + "\",";
                            result += "\"transactor\":\"" + u.getPerformer() + "\"";
                        }
                        result += "}]";
                    } else {
                        result = "[{\"returnError\":\"用户名或密码错误！\"}]";
                    }
                    return result;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (list.size() > 0) {
                result = "[{";
                if (strUserName.equals("nyj")) {
                    for (user_table u : list) {
                        result += "\"webUrl\":\"" + u.getServicewebaddress() + "?stationName=毛田乡" + "\",";
                        result += "\"weChat\":\"" + u.getServicewechataddress() + "?stationName=毛田乡" + "\",";
                        result += "\"entryTime\":\"" + u.getInputtime() + "\",";
                        result += "\"transactor\":\"" + u.getPerformer() + "\"";
                    }
                } else {
                    for (user_table u : list) {
                        result += "\"webUrl\":\"" + u.getServicewebaddress() + "\",";
                        result += "\"weChat\":\"" + u.getServicewechataddress() + "\",";
                        result += "\"entryTime\":\"" + u.getInputtime() + "\",";
                        result += "\"transactor\":\"" + u.getPerformer() + "\"";
                    }
                }
                result += "}]";
                String userName = list.get(0).getUsername();
                request.getSession().setAttribute("UserName", userName);// 保存了一个user对象进session

                //入库username
                RequestDataByUpdate<String, WeiXinUser> updateRequest = new RequestDataByUpdate<String, WeiXinUser>();
                updateRequest.setParam(String.format("openid='" + request.getSession().getAttribute("openid") + "'"));
                WeiXinUser useInfo = new WeiXinUser();
                useInfo.setUserName(userName);
                updateRequest.setData(useInfo);
                Map<String, String> updateParam = new HashMap<String, String>();
                updateParam.put("method", "wxuserblind");
                updateParam.put("advCode", DbConfig.advCode);
                updateParam.put("sqlType", "update");
                updateParam.put("param", JsonUtil.object2Json(updateRequest));
                String message1 = pc.processRequest(updateParam);
                if (message1.equals("1")) {
                    request.getSession().setAttribute("userInfo", list.get(0));
                }
            } else {
                result = "[{\"returnError\":\"用户名或密码错误！\"}]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getStationId(String town) {
        // TODO 用户登录

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(String.format(" stationname='%s'", town));
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "smallscale_station");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<station_info> list = new ArrayList<station_info>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<station_info>>() {
            });

            if (list.size() > 0) {
                result = "[{";
                for (station_info u : list) {
                    result += "\"stationid\":\"" + u.getStationid() + "\",";
                    result += "\"stationName\":\"" + u.getStationname() + "\"";
                }
                result += "}]";
            } else {
                result = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public String getForestDisaster(HttpServletRequest request) {
        // TODO Auto-generated method stub
        // 病虫害
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            String cropName = request.getParameter("cropName");
            dataBySelect.setParam(" cropname ='" + cropName + "'");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "crop_dist_index");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getlyForestDisaster(HttpServletRequest request) {
        // TODO Auto-generated method stub
        // 病虫害
        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "forest_diseases_index");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String initHourTempTime(String url, String qxDbname, String usr, String psd, HttpServletRequest request) {
        // TODO 小时气温初始化时间

        try {
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"observtime"});
            dataBySelect.setSort(new String[]{"observtime desc"});
            dataBySelect.setLimit(1);
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "msgmediumsmallscale");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        return result;
    }

    @Override
    public String getSingleWarnProduct(HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,bindid,context"});
            dataBySelect.setParam(String.format("producttype like '%s%%' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//starttime
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                result = "[";
                String bindid = list.get(0).getBindid().toString();
                String tableName = "";
                if (producttype.contains("地质灾害")) {
                    tableName = "dz_warning";
                    dataBySelect = new RequestDataBySelect();
                    dataBySelect.setColumns(new String[]{"warn_result"});
                    dataBySelect.setParam(String.format("docid='%s' and state>=2", bindid));//starttime
                    dataBySelect.setLimit(1);
                    map = new HashMap<String, String>();
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("method", tableName);
                    map.put("advCode", DbConfig.advCode);
                    map.put("sqlType", "select");
                    result = pc.processRequest(map);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<dz_warning> listwarn = new ArrayList<dz_warning>();
                    listwarn = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<dz_warning>>() {
                    });
                    if (listwarn.size() > 0) {
                        result = "[";
                        for (dz_warning s : listwarn) {
                            result += "{";
                            result += "\"id\":\"" + list.get(0).getId() + "\",";
                            result += "\"context\":\"" + s.getWarn_result().replaceAll("(\\r\\n|\\n|\\n\\r)", "<br/>") + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    }
                } else if (producttype.contains("山洪")) {
                    tableName = "sl_warning";
                    dataBySelect = new RequestDataBySelect();
                    dataBySelect.setColumns(new String[]{"warn_result"});
                    dataBySelect.setParam(String.format("docid='%s' ", bindid));//starttime
                    dataBySelect.setLimit(1);
                    map = new HashMap<String, String>();
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("method", tableName);
                    map.put("advCode", DbConfig.advCode);
                    map.put("sqlType", "select");
                    result = pc.processRequest(map);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<sl_warning> listwarn = new ArrayList<sl_warning>();
                    listwarn = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<sl_warning>>() {
                    });
                    if (listwarn.size() > 0) {
                        result = "[";
                        for (sl_warning s : listwarn) {
                            result += "{";
                            result += "\"id\":\"" + list.get(0).getId() + "\",";
                            result += "\"context\":\"" + s.getWarn_result().replaceAll("(\\r\\n|\\n|\\n\\r)", "<br/>") + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    }

                } else if (producttype.contains("森林火险")) {
                    tableName = "hxyj_warning";
                    dataBySelect = new RequestDataBySelect();
                    dataBySelect.setColumns(new String[]{"warn_result"});
                    dataBySelect.setParam(String.format("docid='%s' ", bindid));//starttime
                    dataBySelect.setLimit(1);
                    map = new HashMap<String, String>();
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("method", tableName);
                    map.put("advCode", DbConfig.advCode);
                    map.put("sqlType", "select");
                    result = pc.processRequest(map);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<hxyj_warning> listwarn = new ArrayList<hxyj_warning>();
                    listwarn = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<hxyj_warning>>() {
                    });
                    if (listwarn.size() > 0) {
                        result = "[";
                        for (hxyj_warning s : listwarn) {
                            result += "{";
                            result += "\"id\":\"" + list.get(0).getId() + "\",";
                            result += "\"context\":\"" + s.getWarn_result().replaceAll("(\\r\\n|\\n|\\n\\r)", "<br/>") + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    }
                } else {
                    for (base_product s : list) {
                        result += "{";
                        result += "\"id\":\"" + s.getId() + "\",";
                        result += "\"context\":\"" + s.getContext() + "\"";
                        result += "},";
                    }
                    result = result.substring(0, result.length() - 1) + "]";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getSingleProduct(HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            dataBySelect.setColumns(new String[]{"id,context"});
            dataBySelect.setParam(String.format("producttype like  '%%%s%%' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//starttime
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });
            if (list.size() > 0) {
                result = "[";
                for (base_product s : list) {
                    result += "{";
                    result += "\"id\":\"" + s.getId() + "\",";
                    result += "\"context\":\"" + s.getContext() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }


    @Override
    public List<msgmediumsmallscale> getskPoint(DPoint Dpoint) {
        // TODO 灾点查询
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        Date nowdate = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
        String nowtime = simpleDateFormat.format(nowdate) + ":00:00";
        if (!StringUtil.IsNullOrEmpty(Dpoint.getCounty())) {
            strWhere.append(String.format(" and county='%s'", Dpoint.getCounty()));
        }

        if (!StringUtil.IsNullOrEmpty(Dpoint.getStations().toString())) {
            StringBuilder stationStr = new StringBuilder();
            stationStr.append("(");
            for (String s : Dpoint.getStations()) {
                stationStr.append("'" + s + "',");
            }
            String stationString = stationStr.substring(0, stationStr.length() - 1);
            stationString += (")");
            strWhere.append(String.format(" and stationname in%s", stationString));
        }
        if (!StringUtil.IsNullOrEmpty(nowtime)) {
            strWhere.append(String.format(" and observtime='%s'", nowtime));// nowtime"2019-09-05 12:00:00"nowtime
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_type())) {
            strWhere.append(String.format(" and dis_type='%s'", Dpoint.getDis_type()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_level())) {
            strWhere.append(String.format(" and dis_level='%s'", Dpoint.getDis_level()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDanger_level())) {
            strWhere.append(String.format(" and danger_level='%s'", Dpoint.getDanger_level()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.qxConn, selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public Object getTownSta(String starttime, String sc, String sx) {
        // TODO 灾点查询
//		DbContextHolder.setDbType("yj");//数据库
//		return forecastInfoMapper.getDPoint(selectKey);
        Object listData = new ArrayList<>();
        List<tower_station> townData = new ArrayList<tower_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        try {
            selectParam.put("method", "tower_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.zyConn, selectParam);
            townData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tower_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        listData = getTownskPoint(townData, starttime, sc, sx);
        return listData;
    }

    public Object getTownskPoint(List<tower_station> townData, String starttime, String sc, String sx) {
        // TODO 灾点查询
//		DbContextHolder.setDbType("yj");//数据库
//		return forecastInfoMapper.getDPoint(selectKey);
        List<thunder_fcst> listData = new ArrayList<thunder_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        String checktime = starttime + ":00:00";
        selectRequest.setColumns(new String[]{"distinct stationname", "lon", "lat", "predictprobability",
                "predictlevel", "reporttime"});
        selectRequest.setParam(
                "reporttime='" + checktime + "' and forecasttime='" + sc + "' and forecastntimes='" + sx + "'");// checktime
        selectRequest.setSort(new String[]{"reporttime asc"});
        try {
            selectParam.put("method", "thunder_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.zyConn, selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<thunder_fcst>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        List<Object> result = new ArrayList<>();
        if (listData.size() == 0) {
            return null;
        } else {
            for (tower_station t : townData) {
                thunder_fcst newthunder = new thunder_fcst();
                double distance = -999.0;
                for (thunder_fcst thunderFcst : listData) {
                    double xvalue = Double.parseDouble(t.getLatitude()) - thunderFcst.getLat();
                    double yvalue = Double.parseDouble(t.getLongitude()) - thunderFcst.getLon();
                    if (distance < xvalue * xvalue - yvalue - yvalue) {
                        distance = xvalue * xvalue - yvalue - yvalue;
                        newthunder.setLat(Double.parseDouble(t.getLatitude()));
                        newthunder.setStationname(t.getStationname());
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        newthunder.setLon(Double.parseDouble(t.getLongitude()));
                        newthunder.setStringtime(simpleDateFormat.format(thunderFcst.getReporttime()));
                        newthunder.setPredictlevel(thunderFcst.getPredictlevel());
                        newthunder.setPredictprobability(thunderFcst.getPredictprobability());
                    }
                }
                result.add(newthunder);
            }
            return result;
        }
    }

    @Override
    public List<TownshipForecast> getfcstPoint(TownshipForecastKey newestDate, String[] stations) {
        // TODO 灾点查询
//		DbContextHolder.setDbType("yj");//数据库
//		return forecastInfoMapper.getDPoint(selectKey);
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("timechar");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
//			strWhere.append(String.format(" and datechar='%s'", "2019-09-27"));
        }
        if (!StringUtil.IsNullOrEmpty(stations.toString())) {
            StringBuilder stationStr = new StringBuilder();
            stationStr.append("(");
            for (String s : stations) {
                stationStr.append("'" + s + "',");
            }
            String stationString = stationStr.substring(0, stationStr.length() - 1);
            stationString += (")");
            strWhere.append(String.format(" and stationname in%s", stationString));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", newestDate.getNTimes(),
                    newestDate.getNTimes() - 24));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecast");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = HttpRequest.get(DbConfig.qxConn, selectParam, true).body();
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getskPoint1(DPoint Dpoint) {
        // TODO 灾点查询
//		DbContextHolder.setDbType("yj");//数据库
//		return forecastInfoMapper.getDPoint(selectKey);
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        Date nowdate = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
        String nowtime = simpleDateFormat.format(nowdate) + ":00:00";
        if (!StringUtil.IsNullOrEmpty(Dpoint.getCounty())) {
            strWhere.append(String.format(" and county='%s'", Dpoint.getCounty()));
        }
        if (!StringUtil.IsNullOrEmpty(nowtime)) {
            strWhere.append(String.format(" and observtime='%s'", nowtime));// nowtime"2019-09-05 12:00:00"nowtime
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_type())) {
            strWhere.append(String.format(" and dis_type='%s'", Dpoint.getDis_type()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_level())) {
            strWhere.append(String.format(" and dis_level='%s'", Dpoint.getDis_level()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDanger_level())) {
            strWhere.append(String.format(" and danger_level='%s'", Dpoint.getDanger_level()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.qxConn, selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<TownshipForecast> getfcstPoint1(TownshipForecastKey newestDate) {
        // TODO 灾点查询
//		DbContextHolder.setDbType("yj");//数据库
//		return forecastInfoMapper.getDPoint(selectKey);
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        //columns.add(String.format("REPLACE(REPLACE(StationName,'%s','顺庆'),'%s','嘉陵') as StationName", DbConfig.HFZ,DbConfig.ZFGC));
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("timechar");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid in (%s)", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
//			strWhere.append(String.format(" and datechar='%s'", "2019-09-27"));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", newestDate.getNTimes(),
                    newestDate.getNTimes() - 24));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecast");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = HttpRequest.get(DbConfig.qxConn, selectParam, true).body();
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<waterlogging_pointinfo> getwaterlogpnt() {
        // TODO 易涝点
        List<waterlogging_pointinfo> listData1 = new ArrayList<waterlogging_pointinfo>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "waterlogging_pointinfo");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<waterlogging_pointinfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData1;
    }

    @Override
    public List<msgmediumsmallscale> getcityskPoint(String stationname) {
        // TODO 灾点查询
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        Date nowdate = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
        String nowtime = simpleDateFormat.format(nowdate) + ":00:00";
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            strWhere.append(String.format(" and stationname='%s'", stationname));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setLimit(1);
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.qxConn, selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public String getmoniwaring(String url, String usr, String psd, HttpServletRequest request) {
        try {
            String type = request.getParameter("type");//check确认是否有监控数据 detail 站点详情
            Date nowtime = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String endtime = simpleDateFormat.format(nowtime) + " 23:59:59";
            String starttime = simpleDateFormat.format(nowtime) + " 00:00:00";
            String monitorelement = "PRE";

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id,stationid,monitorvalue,warningtime,warningtype,monitortype"});
            dataBySelect.setParam(String.format("monitorelement = '%s' and time>='%s' and time<='%s'",
                    monitorelement, starttime, endtime));//starttime
            dataBySelect.setSort(new String[]{"warningtime desc"});

            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "warn_moni_info");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);

            if (result.equals("")) {
                result = "[]";
            }
            List<warn_moni_info> list = new ArrayList<warn_moni_info>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<warn_moni_info>>() {
            });

            if (list.size() > 0 && "check".equals(type)) {
                result = "[{\"check\":\"true\"}]";
            } else {
                if (list.size() == 0) {
                    result = "[]";
                    return result;
                }

                String stationid = "(";//拼接 （)
                for (warn_moni_info info : list) {
                    stationid += "'" + info.getStationid() + "',";
                }
                stationid = stationid.substring(0, stationid.length() - 1);
                stationid += ")";

                RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
                Map<String, String> map1 = new HashMap<String, String>();
                dataBySelect1.setColumns(new String[]{"stationid,stationname "});
                dataBySelect1.setParam(" stationid  in " + stationid + "");
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", "smallscale_station");
                map1.put("sqlType", "select");
                String res = pc.processRequest(map1);
                List<station_info> list1 = new ArrayList<station_info>();
                list1 = JsonUtil.jsonStr2TypeReference(res, new TypeReference<List<station_info>>() {
                });
                //处理数据进行分组
                List<Map> listdata = new LinkedList<Map>();
                List<Map> bigmapcontain = new LinkedList<>(); //
                List<Map> tt = new LinkedList<>();

                Map<String, Object> tempmap1 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap1);
                Map<String, Object> tempmap2 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap2);
                Map<String, Object> tempmap3 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap3);
                Map<String, Object> tempmap4 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap4);
                Map<String, Object> tempmap5 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap5);
                Map<String, Object> tempmap6 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap6);
                Map<String, Object> tempmap7 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap7);
                Map<String, Object> tempmap8 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap8);
                Map<String, Object> tempmap9 = new HashMap<String, Object>();
                bigmapcontain.add(tempmap9);
                for (warn_moni_info info : list) {
                    boolean flag = false;
                    for (int i = 0; i < listdata.size(); i++) {
                        Map<String, Object> temp = listdata.get(i);
                        if (info.getWarningtype().equals(temp.get("warningtype")) &&
                                info.getMonitortype().equals(temp.get("Monitortype"))) {
                            //共计
                            Integer a = (Integer) temp.get("total");
                            a += 1;
                            temp.put("total", a);
                            //最大雨量 和站点

                            HashMap<String, String> hashMap = new HashMap<String, String>();
                            hashMap.put("rain", info.getMonitorvalue().toString());
                            hashMap.put("stationid", info.getStationid());
                            tt.add(hashMap);
                            temp.put("Raincodtion", tt);

                            flag = true;
                        }
                    }//内循环结束
                    if (!flag) {
                        //l两个集合出入栈 包装引用不会丢失
                        Map<String, Object> temp = ((LinkedList<Map>) bigmapcontain).getFirst();//new HashMap<String ,Object>();

                        temp.put("warningtype", info.getWarningtype());// 3小时最大降水量 》20
                        temp.put("total", 1);//共计
                        HashMap<String, String> hashMap = new HashMap<String, String>();
                        hashMap.put("rain", info.getMonitorvalue().toString());
                        hashMap.put("stationid", info.getStationid());
                        tt.add(hashMap);
                        temp.put("Raincodtion", tt);

                        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        temp.put("waringtime", date.format(info.getWarningtime()));//时间
                        temp.put("Monitortype", info.getMonitortype());//时间 1  或3
                        listdata.add(temp);
                        ((LinkedList<Map>) bigmapcontain).removeFirst();
                    }

                }

                result = "[";
                for (int i = 0; i < listdata.size(); i++) {
                    result += "{\"raincolloect\":";

                    Map mymap = listdata.get(i);
                    List<Map> temp3 = (List<Map>) mymap.get("Raincodtion");

                    for (int j = 0; j < temp3.size(); j++) {
                        if (j == 0) {
                            result += "[";
                        }
                        String stationname = "";
                        Map mmm = temp3.get(j);
                        String stationid1 = mmm.get("stationid").toString();
                        String rain = mmm.get("rain").toString();
                        result += "{";
                        for (station_info station : list1) {
                            if (station.getStationid().equals(stationid1)) {
                                stationname = station.getStationname();
                            }

                            result += "\"stationname\":\"" + stationname + "\",";

                            result += "\"rain\":\"" + rain + "\",";
                        }
                        result = result.substring(0, result.length() - 1) + "},";
                    }
                    result = result.substring(0, result.length() - 1) + "],";

                    String Monitortype = mymap.get("Monitortype").toString();
                    result += "\"monitortype\":\"" + Monitortype + "\",";


                    String waringtime = mymap.get("waringtime").toString();
                    result += "\"warningtime\":\"" + waringtime + "\",";

                    String warningtype = mymap.get("warningtype").toString();
                    result += "\"warningtype\":\"" + warningtype + "\",";

                    String total = mymap.get("total").toString();
                    result += "\"total\":\"" + total + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";

            }


        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    // 安监初始化
    @Override
    public List<special_srv_station> getAnjianPoint(String staName) {
        // TODO Auto-generated method stub
        List<special_srv_station> newDate = new ArrayList<special_srv_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("stationname like '%" + staName + "%'");
        try {
            selectParam.put("method", "special_srv_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.qxConn, selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<special_srv_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return newDate;
    }

    // 安监预报
    @Override
    public List<TownshipForecast> getAnjianFcst(String time, String sc, String sx, String r, String lon, String lat) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(time)) {
            whereCount++;
            strWhere.append(String.format("datechar='%s'", time));
        }
        if (!StringUtil.IsNullOrEmpty(sc)) {
            strWhere.append(String.format(" and timechar='%s'", sc));
        }
        if (!StringUtil.IsNullOrEmpty(sx) && Integer.parseInt(sx) > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", Integer.parseInt(sx),
                    Integer.parseInt(sx) - 24));
        }
//        if (!StringUtil.IsNullOrEmpty(r)) {
//            strWhere.append(" and sqrt((longitude - '" + lon + "')^2 + (latitude - '" + lat + "')^2) < '" + r + "'");
//        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (DateTime.UserMainDataTable(sdf.parse(time), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecast");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = HttpRequest.get(DbConfig.qxConn, selectParam, true).body();
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    // 安监实况
    @Override
    public List<MsgMediumSmallScale> qxElementQuery(ActualElemQuery elemQuery) {
        List<MsgMediumSmallScale> dataList = new ArrayList<MsgMediumSmallScale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        String type = "";
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observTime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        // if (element != null ) {
        columns.add("sum(rain) as rain");
        selectRequest.setSort(new String[]{"rain desc"});
        strWhere.append(" and rain <> -65535");
        type = "avg";
        // 温度统计
        columns.add("cast(" + type + "(cast(DryBulbTemp as numeric(18,1))) as FLOAT) as DryBulbTemp");
        strWhere.append(" and DryBulbTemp <> -65535");
        selectRequest.setSort(new String[]{"DryBulbTemp desc"});
        // 风速
        columns.add("max(InstantWindV) as InstantWindV");
        strWhere.append(" and InstantWindV <> -65535");
        selectRequest.setSort(new String[]{"InstantWindV desc"});
        // 风向
        columns.add("max(InstantWindD) as InstantWindD");
        strWhere.append(" and InstantWindD <> -65535");
        selectRequest.setSort(new String[]{"InstantWindD desc"});
        // 本站气压
        columns.add("avg(StationPress) as StationPress");
        strWhere.append(" and StationPress <> -65535");
        selectRequest.setSort(new String[]{"StationPress desc"});
        // }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = httpUtil.sendPost(DbConfig.qxConn, selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }

        return dataList;
    }

    @Override
    public String getRainInfo(HttpServletRequest request) {
        try {
            Date nowdate = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
            String starttime = simpleDateFormat.format(nowdate) + ":00:00";
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"rain"});
            dataBySelect.setParam("observtime='" + starttime + "'");//2019-09-11 15:00:00
            dataBySelect.setSort(new String[]{"rain desc"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "msgmediumsmallscale");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<msgmediumsmallscale> list = new ArrayList<msgmediumsmallscale>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<msgmediumsmallscale>>() {
            });
            if (list.size() > 0) {
                int level1 = 0;
                int level2 = 0;
                int level3 = 0;
                int level4 = 0;
                int level5 = 0;
                float maxrain = -1;
                for (int i = 0; i < list.size(); i++) {
                    if (maxrain <= list.get(i).getRain()) {
                        maxrain = list.get(i).getRain();
                    }
                    if (list.get(i).getRain() > 0 && list.get(i).getRain() < 10) {
                        level1 += 1;
                    } else if (list.get(i).getRain() > 10 && list.get(i).getRain() < 25) {
                        level2 += 1;
                    } else if (list.get(i).getRain() > 25 && list.get(i).getRain() < 50) {
                        level3 += 1;
                    } else if (list.get(i).getRain() > 50 && list.get(i).getRain() < 100) {
                        level4 += 1;
                    } else if (list.get(i).getRain() > 100) {
                        level5 += 1;
                    }
                }
                result = "[{";
                result += "\"maxrain\":\"" + maxrain + "\"},{";
                result += "\"level1\":\"" + level1 + "\"},{";
                result += "\"level2\":\"" + level2 + "\"},{";
                result += "\"level3\":\"" + level3 + "\"},{";
                result += "\"level4\":\"" + level4 + "\"},{";
                result += "\"level5\":\"" + level5 + "\"";
                result += "}]";
            } else {
                result = "[{";
                result += "\"maxrain\":\"" + "暂无数据" + "\"";
                result += "}]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getProProductList(String url, HttpServletRequest request) {
        // TODO 产品
        try {
            String strBigType = request.getParameter("bigType");// 大类别
            String strSmallType = request.getParameter("smallType");// 小类别
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setSort(new String[]{"maketime desc"});
            dataBySelect.setLimit(1);
            if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                dataBySelect.setParam(String.format("producttype='%s'  and producttype2='%s' and status = '1' ", strBigType, strSmallType));

            } else {
                dataBySelect.setParam(String.format("producttypee='%s' and  status = '1' ", strBigType));
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "summary_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("1=1  and status = '1' ");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                    dataBySelect1
                            .setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
                }
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", "summary_product");
                map1.put("advCode", DbConfig.advCode);
                map1.put("sqlType", "select");
            }
            result = pc.processRequest(map);

            List<summary_product> forecast = new ArrayList<summary_product>();
            forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<summary_product>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "[";
                for (summary_product temp : forecast) {
                    try {
                        String fileId = temp.getId().toString().trim();
                        String serviceFilePath = "";
                        // 下载
                        String fileName = temp.getProductname().trim();
                        String[] split = fileName.split("\\.");
                        fileName = split[0] + ".pdf";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path
                                + "/Temp/product/";
                        String serviceUrl = basePath + fileName;
                        String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                        serviceFilePath = urlpath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件
                        if (!serviceFile.exists()) {// 把文件上传到服务器
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("id", fileId);
                            queryMap.put("table_name", "summary_product");
                            queryMap.put("collectionName", "pdf_file");
                            queryMap.put("advCode", DbConfig.advCode);
                            byte[] data = ms.selectData(queryMap);
                            if (data == null) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.equals("")) {
                            serviceFilePath = serviceUrl;
                        }
                        String productpath = serviceFilePath;

                        result += "{";
                        result += "\"id\":\"" + fileId + "\",";
                        result += "\"productName\":\"" + temp.getProductname() + "\",";
                        result += "\"productType\":\"" + temp.getProducttype() + "\",";
                        result += "\"productPath\":\"" + productpath + "\",";
                        result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                        result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                        result += "\"maker\":\"" + temp.getMaker() + "\"";
                        result += "},";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1) + "]";
                } else {
                    result += "]";
                }

                result = result.replace("\\\\", "\\");
            } else {
                result = "[]";
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
        }
        return result;
    }

    @Override
    public String GetDisWeatherDayImg(String distype, String localPath, HttpServletRequest request) {
        MongoService1 mongoService = new MongoService1();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String paths = "";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(new Date());
        String urls = DbConfig.IP + request.getContextPath();
        String fileName = distype + time + ".jpg";
        File serviceFile = new File(localPath + fileName);
        if (!serviceFile.exists()) {
            // 从mongdb获取图片
            Map<String, Object> map1 = new HashMap<String, Object>();
            map1.put("type", distype);
            map1.put("datechar", time);
            map1.put("collectionName", "disweather_png_file");
            map1.put("advCode", DbConfig.advCode);
            byte[] data = ms.selectData(map1);
            if (data == null) {
                paths = "images/tourinfo/none.jpg";
            } else {
                FileUtil.bytesToFile(data, localPath + fileName);
                paths = "Temp\\" + fileName;
                paths = paths.replace("\\", "/");
            }
        } else {
            paths = "Temp\\" + fileName;
            paths = paths.replace("\\", "/");
        }
        String result = "[\"" + urls + "/" + paths + "\"]";

        return result;
    }

    @Override
    public String getFirePoint(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 火源点
        try {
            String starttime = request.getParameter("starttime");
            String endtime = request.getParameter("endtime");
            starttime = starttime + " 00:00:00";
            endtime = endtime + " 23:59:59";


            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"coordinates"});
            dataBySelect.setParam("datechar between '" + starttime + "' and '" + endtime + "'");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "satellitenephoram3");
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<satellitenephoram3> flist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<satellitenephoram3>>() {
            });

            List<FirePoint> pointlist = new ArrayList<FirePoint>();

            for (int i = 0; i < flist.size(); i++) {
                String[] strdata = flist.get(i).getCoordinates().split(";");

                for (int j = 0; j < strdata.length; j++) {
                    String[] lonlat = strdata[j].split(",");
                    String lon = lonlat[0].substring(0, lonlat[0].indexOf(".") + 2);
                    String lat = lonlat[1].substring(0, lonlat[1].indexOf(".") + 2);
                    Double d_lon = Double.parseDouble(lon);
                    Double d_lat = Double.parseDouble(lat);

                    FirePoint firePoint = new FirePoint();
                    firePoint.setLon(d_lon);
                    firePoint.setLat(d_lat);
					/*firePoint.setX(ltDot.x);
					firePoint.setY(ltDot.y);*/
                    pointlist.add(firePoint);
                }
            }

            if (flist.size() > 0) {
//				rs.previous();
                result = "[";
                for (FirePoint f : pointlist) {
                    result += "{";
                    result += "\"name\":\"" + "" + "\",";
                    result += "\"lon\":\"" + f.getLon() + "\",";
                    result += "\"lat\":\"" + f.getLat() + "\"";
                    result += "},";
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public Object getDPoint(DPoint Dpoint, String type) {
        // TODO 灾点查询
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(Dpoint.getCounty())) {
            strWhere.append(String.format(" and county='%s'", Dpoint.getCounty()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_type())) {
            strWhere.append(String.format(" and dis_type='%s'", Dpoint.getDis_type()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDis_level())) {
            strWhere.append(String.format(" and dis_level='%s'", Dpoint.getDis_level()));
        }
        if (!StringUtil.IsNullOrEmpty(Dpoint.getDanger_level())) {
            strWhere.append(String.format(" and danger_level='%s'", Dpoint.getDanger_level()));
        }
        if (type.equals("anjian")) {
            strWhere.append(String.format(" and flag like '%s%%'", "安监应急"));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            if (type.equals("dz") || type.equals("sl")) {
                List<potential_points> listData1 = new ArrayList<potential_points>();
                selectParam.put("method", "potential_points");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
                });
                if (listData1.equals("[]")) {
                    return null;
                } else {
                    return listData1;
                }
            } else if (type.equals("forest")) {
                List<fire_history> listData1 = new ArrayList<fire_history>();
                selectParam.put("method", "fire_history");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<fire_history>>() {
                });
                if (listData1.equals("[]")) {
                    return null;
                } else {
                    return listData1;
                }
            } else if (type.equals("cityfire")) {
                List<ccshx_imp_dot> listData1 = new ArrayList<ccshx_imp_dot>();
                selectParam.put("method", "ccshx_imp_dot");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ccshx_imp_dot>>() {
                });
                if (listData1.equals("[]")) {
                    return null;
                } else {
                    int flag = 0;
                    for (ccshx_imp_dot zsyb : listData1) {
                        List<msgmediumsmallscale> info = getcityskPoint(zsyb.getJoinstation());
                        if (info.size() == 0) {
                            listData1.get(flag).setDrybulbtemp(0);
                            listData1.get(flag).setRain(0);
                            listData1.get(flag).setInstantwindv(0);
                            flag++;
                        } else {
                            listData1.get(flag).setDrybulbtemp(info.get(0).getDrybulbtemp());
                            listData1.get(flag).setRain(info.get(0).getRain());
                            listData1.get(flag).setInstantwindv(info.get(0).getInstantwindv());
                            flag++;
                        }

                    }
                    return listData1;
                }
            } else if (type.equals("anjian")) {
                List<special_srv_station> listData1 = new ArrayList<special_srv_station>();
                selectParam.put("method", "special_srv_station");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<special_srv_station>>() {
                });
                if (listData1.equals("[]")) {
                    return null;
                } else {
                    return listData1;
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;
    }

    @Override
    public String multiProductList(HttpServletRequest request) {
        // TODO 产品
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strBigType = request.getParameter("bigType");// 大类别
            String strSmallType = request.getParameter("smallType");// 小类别
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(" maketime between '" + strDate1 + "' and '" + strDate2 + "' and 1=1");
            dataBySelect.setSort(new String[]{"maketime desc"});
            if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "producttype like '" + strSmallType + "%%'"));
            }
            Map<String, String> map = new HashMap<String, String>();
            String tableName = "";
            switch (strBigType) {
                case "公共气象": {
                    tableName = "base_product";
                }
                ;
                break;
                case "电力气象": {
                    tableName = "power_product";
                }
                ;
                break;
                case "人保气象": {
                    tableName = "agri_product";
                }
                ;
                break;
                case "农业气象": {
                    tableName = "agri_product";
                }
                ;
                break;
            }
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", tableName);
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("1=1");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                    dataBySelect1
                            .setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
                }
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", tableName);
                map1.put("advCode", DbConfig.advCode);
                map1.put("sqlType", "select");
            }
            result = pc.processRequest(map);

            switch (strBigType) {
                case "公共气象": {
                    List<base_product> forecast = new ArrayList<base_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (base_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }

                                String serviceFilePath = "";
                                // 下载
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载图片到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;

                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                break;
                case "电力气象": {
                    List<power_product> forecast = new ArrayList<power_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<power_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (power_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }


                                String serviceFilePath = "";
                                // 下载
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载图片到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;

                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }

                }
                ;
                break;
                case "人保气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }

                                String serviceFilePath = "";
                                // 下载
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载图片到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;

                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
                case "农业气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    //转为pdf
                                    collectionName = "pdf_file";
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }

                                String serviceFilePath = "";
                                // 下载
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载图片到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;


                                // mongodb下载参数
                                String param = "collectionName=" + collectionName + "&id=" + fileId + "&table_name="
                                        + tableName + "&resultType=" + resultType;
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
        }
        return result;
    }

    @Override
    public String getWXDZwarning(String url, String usr, String psd, HttpServletRequest request) {
        try {
            String producttype = request.getParameter("producttype");
            String starttime = request.getParameter("starttime");
            starttime = starttime + " 00:00:00";
            //starttime = "2019-10-01"+" 00:00:00";
            String endtime = request.getParameter("endtime");
            endtime = endtime + " 23:59:59";

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setColumns(new String[]{"id,bindid"});
            dataBySelect.setParam(String.format("producttype = '%s' and maketime>='%s' and maketime<='%s'",
                    producttype, starttime, endtime));//starttime
            dataBySelect.setSort(new String[]{"id DESC"});
            dataBySelect.setLimit(1);
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "base_product");
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            List<base_product> list = new ArrayList<base_product>();
            list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
            });

            if (list.size() != 1) {
                result = "[]";
            } else {
                String bindid = list.get(0).getBindid();

                RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
                Map<String, String> map1 = new HashMap<String, String>();
                dataBySelect1.setColumns(new String[]{"warn_result"});
                dataBySelect1.setParam(" docid ='" + bindid + "'");
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", "dz_warning");
                map1.put("advCode", DbConfig.advCode);
                map1.put("sqlType", "select");
                result = pc.processRequest(map1);
                if (result.equals("")) {
                    result = "[]";
                }
                List<dz_warning> list1 = new ArrayList<dz_warning>();
                list1 = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<dz_warning>>() {
                });
                if (list1.size() > 0) {
                    result = "[";
                    for (dz_warning s : list1) {
                        result += "{";
                        result += "\"context\":\"" + s.getWarn_result().trim() + "\"";
                        result += "},";

                    }
                    result = result.substring(0, result.length() - 1) + "]";
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String nongshiYB(String url, String usr, String psd, HttpServletRequest request) {
        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strBigType = request.getParameter("bigType");// 大类别
            String strSmallType = request.getParameter("smallType");// 小类别
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }
            String[] product = {"收晒", "喷药", "施肥", "灌溉"};
            List<agri_product> forecast = new ArrayList<agri_product>();
            for (int i = 0; i < product.length; i++) {
                RequestDataBySelect dataBySelect = new RequestDataBySelect();
                dataBySelect.setParam(" maketime between '" + strDate1 + "' and '" + strDate2 + "' and productname  like '%" + product[i] + "%' ");
                dataBySelect.setSort(new String[]{"maketime desc"});
                dataBySelect.setLimit(1);
                if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                    dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
                }
                Map<String, String> map = new HashMap<String, String>();
                map.put("param", JsonUtil.object2Json(dataBySelect));
                map.put("method", "agri_product");
                map.put("advCode", DbConfig.advCode);
                map.put("sqlType", "select");
                result = pc.processRequest(map);
                if (result.equals("")) {
                    result = "[]";
                }
                List<agri_product> forecasttemp = new ArrayList<agri_product>();
                forecasttemp = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                });
                if (forecasttemp.size() > 0) {
                    forecast.add(forecasttemp.get(0));
                }
            }

            if (forecast != null && forecast.size() > 0) {
                result = "[";
                for (agri_product temp : forecast) {
                    try {
                        // 下载地址
                        String fileName = temp.getProductname().trim();
//                        String fileType = fileName.substring(fileName.length() - 3);// 文件中不能出现点符号
//                        String collectionName = "";// mongodb集合名称
                        String fileId = temp.getId().toString().trim();
//                        if (fileType.equals("jpg"))// jpg图片
//                        {
//                            collectionName = "image_file";
//                        }
                        String serviceFilePath = "";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path + "/Temp/Image/";
                        String serviceUrl = basePath + fileName;
                        String urlPath;
                        if (operatingSystem.equals("Windows")){
                            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Image\\";
                        }else {
                            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Image/";
                        }
                        serviceFilePath = urlPath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件

                        if (!serviceFile.exists()) {// 把文件上传到服务器
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("id", fileId);
                            queryMap.put("table_name", "agri_product");
                            queryMap.put("advCode", DbConfig.advCode);
                            queryMap.put("collectionName", "image_file");
                            byte[] data = ms.selectData(queryMap);
                            if (data == null) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.isEmpty()) {
                            serviceFilePath = serviceUrl;
                        }
                        String productPath = serviceFilePath;
                        result += "{";
                        result += "\"id\":\"" + fileId + "\",";
                        result += "\"productName\":\"" + temp.getProductname() + "\",";
                        result += "\"productType\":\"" + temp.getProducttype() + "\",";
                        result += "\"productPath\":\"" + productPath + "\",";
                        result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                        result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                        result += "\"maker\":\"" + temp.getMaker() + "\"";
                        result += "},";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1) + "]";
                } else {
                    result += "]";
                }
                result = result.replace("\\\\", "\\");
            } else {
                result = "[]";
            }


            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
        }
        return result;
    }


    public String imageUrl(HttpServletRequest request, String productname, String paramid) {
        //下载图片
        String serviceFilePath = "";
        // 下载
        String fileName = productname;
        String path = request.getContextPath();
        String basePath = DbConfig.IP + path
                + "/Temp/Images/";
        String serviceUrl = basePath + fileName;
        String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Images\\";
        serviceFilePath = urlpath + fileName;// 服务器文件
        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
        // 如果目录中不存在文件，下载雷达文件到temp目录
        File serviceFile = new File(serviceFilePath);// 服务器文件
        if (!serviceFile.exists()) {// 把文件上传到服务器
            Map<String, Object> queryMap = new HashMap<String, Object>();
            queryMap.put("id", paramid);
            queryMap.put("table_name", "agri_product");
            queryMap.put("advCode", DbConfig.advCode);
            queryMap.put("collectionName", "image_file");
            byte[] data = ms.selectData(queryMap);
            if (data == null) {
                serviceFilePath = "";
            } else {
                FileUtil.bytesToFile(data, serviceFilePath);
            }
        }
        if (!serviceFilePath.equals("")) {
            serviceFilePath = serviceUrl;
        }
        String imageUrl = serviceFilePath;
        return imageUrl;
    }


    @Override
    public String getQuHuaProduct(HttpServletRequest request) {
        // TODO 农业区划图

        String paths = "";
        String smallType = request.getParameter("smallType");
        String bigType = "";
        String param = "";
        result = "[";
        if (smallType.equals("水稻")) {
            result += "{\"producttype\":\"" + "作物分布图" + "\",";
            result += "\"productname\":\"" + "水稻.jpg" + "\",";
            bigType = "作物分布图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "水稻.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .png
        }

        if (smallType.equals("甘蔗")) {
            result += "{\"producttype\":\"" + "作物分布图" + "\",";
            result += "\"productname\":\"" + "甘蔗.jpg" + "\",";
            bigType = "作物分布图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "甘蔗.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .png
        }


        if (smallType.equals("棉花")) {
            result += "{\"producttype\":\"" + "作物区划图" + "\",";
            result += "\"productname\":\"" + "棉花.jpg" + "\",";
            bigType = "作物区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "棉花.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }

        if (smallType.equals("双季稻")) {
            result += "{\"producttype\":\"" + "作物区划图" + "\",";
            result += "\"productname\":\"" + "双季稻.jpg" + "\",";
            bigType = "作物区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "双季稻.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }

        if (smallType.equals("烟草")) {
            result += "{\"producttype\":\"" + "作物区划图" + "\",";
            result += "\"productname\":\"" + "烟草.jpg" + "\",";
            bigType = "作物区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "烟草.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }
        if (smallType.equals("油茶")) {
            result += "{\"producttype\":\"" + "作物区划图" + "\",";
            result += "\"productname\":\"" + "油茶.jpg" + "\",";
            bigType = "作物区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "油茶.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }


        if (smallType.equals("倒春寒灾害风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "倒春寒灾害风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "倒春寒灾害风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .png
        }

        if (smallType.equals("干旱风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "干旱风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "干旱风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }
        if (smallType.equals("高温热害风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "高温热害风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "高温热害风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }
        if (smallType.equals("寒露风灾害风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "寒露风灾害风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "寒露风灾害风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }

        if (smallType.equals("洪涝风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "洪涝风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "洪涝风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }

        if (smallType.equals("五月低温灾害风险")) {
            result += "{\"producttype\":\"" + "灾害区划图" + "\",";
            result += "\"productname\":\"" + "五月低温灾害风险.jpg" + "\",";
            bigType = "灾害区划图";
            param = getImageId(bigType, smallType);
            if (param.equals("[]")) {
                paths = "images/tourinfo/none.jpg";
            } else {
                String productname = "五月低温灾害风险.jpg";
                //获取图片
                paths = imageUrl(request, productname, param);
            }
            result += "\"url\":\"" + paths + "\"}";// .jpg
        }
        result = result + "]";
        return result;
    }

    @Override
    public String getwxProductList(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 产品

        try {
            String timeRange = request.getParameter("timeRange");
            timeRange = timeRange.substring(1, timeRange.length() - 1);
            String strDate1 = timeRange.split(",")[0]; // 开始时间
            String strDate2 = timeRange.split(",")[1]; // 开始时间
            String strBigType = request.getParameter("bigType");// 大类别
            String strSmallType = request.getParameter("smallType");// 小类别
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setParam(" maketime between '" + strDate1 + "' and '" + strDate2 + "' and 1=1");
            dataBySelect.setSort(new String[]{"maketime desc"});
            if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
            }
            Map<String, String> map = new HashMap<String, String>();
            String tableName = "";
            switch (strBigType) {
                case "公共气象": {
                    tableName = "base_product";
                }
                ;
                break;
                case "电力气象": {
                    tableName = "power_product";
                }
                ;
                break;
                case "人保气象": {
                    tableName = "agri_product";
                }
                ;
                break;
                case "农业气象": {
                    tableName = "agri_product";
                }
                ;
                break;
            }
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", tableName);
            map.put("advCode", DbConfig.advCode);
            map.put("sqlType", "select");
            result = pc.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("1=1");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                if (!StringUtil.IsNullOrEmpty(strSmallType)) {
                    dataBySelect1
                            .setParam(dataBySelect.getParam().replace("1=1", "producttype='" + strSmallType + "'"));
                }
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", tableName);
                map1.put("advCode", DbConfig.advCode);
                map1.put("sqlType", "select");
                result = pc.processRequest(map1);
            }

            switch (strBigType) {
                case "公共气象": {
                    List<base_product> forecast = new ArrayList<base_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<base_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (base_product temp : forecast) {
                            try {
                                // 下载地址
                                String serviceFilePath = "";
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
//                                String[] split1 = fileName.split("\\.");
//                                fileName = split1[0] + ".pdf";
                                if (fileType.contains("doc"))// doc文本
                                {
                                    //
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载雷达文件到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件


                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }

                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;

                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
                case "电力气象": {
                    List<power_product> forecast = new ArrayList<power_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<power_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (power_product temp : forecast) {
                            try {
                                // 下载地址
                                String serviceFilePath = "";
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/Product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载雷达文件到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }

                }
                break;
                case "人保气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String serviceFilePath = "";
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/Product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                // 如果目录中不存在文件，下载雷达文件到temp目录
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }

                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                ;
                break;
                case "农业气象": {
                    List<agri_product> forecast = new ArrayList<agri_product>();
                    forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<agri_product>>() {
                    });
                    if (forecast != null && forecast.size() > 0) {
                        result = "[";
                        for (agri_product temp : forecast) {
                            try {
                                // 下载地址
                                String serviceFilePath = "";
                                String fileName = temp.getProductname().trim();
                                String fileType = fileName.substring(fileName.length() - 3, fileName.length());// 文件中不能出现点符号
                                String collectionName = "";// mongodb集合名称
                                String fileId = temp.getId().toString().trim();
                                String path = request.getContextPath();
                                String basePath = DbConfig.IP + path
                                        + "/Temp/Product/";
                                String serviceUrl = basePath + fileName;
                                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Product\\";
                                serviceFilePath = urlpath + fileName;// 服务器文件
                                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                                File serviceFile = new File(serviceFilePath);// 服务器文件
                                if (fileType.equals("txt"))// txt文本
                                {
                                    collectionName = "txt_file";
                                }
                                if (fileType.contains("doc"))// doc文本
                                {
                                    String[] split = fileName.split("\\.");
                                    fileName = split[0] + ".pdf";
                                    collectionName = "pdf_file";
                                }
                                if (fileType.contains("xls"))// execel文本
                                {
                                    collectionName = "excel_file";
                                }
                                if (!serviceFile.exists()) {// 把文件上传到服务器
                                    Map<String, Object> queryMap = new HashMap<String, Object>();
                                    queryMap.put("id", fileId);
                                    queryMap.put("table_name", tableName);
                                    queryMap.put("advCode", DbConfig.advCode);
                                    queryMap.put("collectionName", collectionName);
                                    byte[] data = ms.selectData(queryMap);
                                    if (data == null) {
                                        serviceFilePath = "";
                                    } else {
                                        FileUtil.bytesToFile(data, serviceFilePath);
                                    }
                                }
                                if (!serviceFilePath.equals("")) {
                                    serviceFilePath = serviceUrl;
                                }
                                String productPath = serviceFilePath;
                                result += "{";
                                result += "\"id\":\"" + fileId + "\",";
                                result += "\"productName\":\"" + temp.getProductname() + "\",";
                                result += "\"productType\":\"" + temp.getProducttype() + "\",";
                                result += "\"productPath\":\"" + productPath + "\",";
                                result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                                result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                                result += "\"maker\":\"" + temp.getMaker() + "\"";
                                result += "},";
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (result.endsWith(",")) {
                            result = result.substring(0, result.length() - 1) + "]";
                        } else {
                            result += "]";
                        }
                        result = result.replace("\\\\", "\\");
                    } else {
                        result = "[]";
                    }
                }
                break;
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
        }
        return result;
    }

    @Override
    public String getProtect(String url, String usr, String psd, HttpServletRequest request) {
        // TODO 环保实况查询
        try {
            String stationname = request.getParameter("stationname");
            RequestDataBySelect dbs = new RequestDataBySelect();
            dbs.setColumns(new String[]{"observtime"});
            dbs.setSort(new String[]{"observtime desc"});
            dbs.setLimit(1);
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("method", "airpollution");
            mp.put("advCode", DbConfig.advCode);
            mp.put("param", JsonUtil.object2Json(dbs));
            mp.put("sqlType", "select");
            result = pc.processRequest(mp);
            if (result.equals("")) {
                result = "[]";
            }
            List<airpollution> lis = new ArrayList<airpollution>();
            lis = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<airpollution>>() {
            });
            if (lis.size() > 0) {
                for (airpollution a : lis) {
                    Date date = a.getObservtime();
                    String fmobt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) + "  数据";
                    RequestDataBySelect dataBySelect = new RequestDataBySelect();
                    dataBySelect.setColumns(new String[]{"stationname,aqi"});
                    dataBySelect
                            .setParam("stationname!='" + stationname + "' and  observtime='" + a.getObservtime() + "'");
                    dataBySelect.setSort(new String[]{"aqi desc"});
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("method", "airpollution");
                    map.put("advCode", DbConfig.advCode);
                    map.put("param", JsonUtil.object2Json(dataBySelect));
                    map.put("sqlType", "select");
                    result = pc.processRequest(map);
                    if (result.equals("")) {
                        result = "[]";
                    }
                    List<airpollution> list = new ArrayList<airpollution>();
                    list = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<airpollution>>() {
                    });
                    String staname;
                    int aqi;
                    if (list.size() > 0) {
                        result = "[";
                        for (airpollution ai : list) {
                            result += "{";
                            result += "\"stationname\":\"" + ai.getStationname().trim() + "\",";
                            result += "\"observtime\":\"" + fmobt + "\",";
                            result += "\"aqi\":\"" + ai.getAqi() + "\"";
                            result += "},";
                        }
                        result = result.substring(0, result.length() - 1) + "]";
                    } else {
                        result = "[]";
                    }
                }
                result = result.substring(0, result.length() - 1) + "]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }

    @Override
    public String getWeekProtection(String url, String usr, String psd, HttpServletRequest request) {
        try {
            String starttime = request.getParameter("starttime");
            String endtime = request.getParameter("endtime");
            String pollution = request.getParameter("pulltion");
            starttime = starttime + "00:00:00";
            endtime = endtime + "23:59:59";
            String stationname = "市二中";

            if (pollution == null && pollution.equals("")) {
                return "[]";
            }
            RequestDataBySelect dbs = new RequestDataBySelect();
            dbs.setColumns(new String[]{"Round(cast(avg(concenpm2p5) as numeric),1)  as concenpm2p5",
                    "Round(cast(avg(concenpm10) as numeric),1) as concenpm10",
                    "Round(cast(avg(concenco) as numeric),1) concenco ",
                    "Round(cast(avg(conceno3) as numeric),1) conceno3 ",
                    "Round(cast(avg(concenso2) as numeric),1) concenso2 ",
                    "Round(cast(avg(concenno2) as numeric),1) concenno2 ",
                    "Round(cast(avg(aqi) as numeric),0) aqi ",
                    "concat(to_char(observtime,'yyyy-MM-dd'),' 00:00:00')  as observtime"});
            dbs.setParam("stationname='" + stationname + "' and observtime >='" + starttime + "' and observtime <= '" + endtime + "'");
            dbs.setSort(new String[]{"observtime asc"});
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("method", "airpollution");
            mp.put("advCode", DbConfig.advCode);
            mp.put("param", JsonUtil.object2Json(dbs));
            mp.put("sqlType", "select");
            String message = pc.processRequest(mp);
            if (message.equals("")) {
                result = "[]";
            }
            List<airpollution> lis = new ArrayList<airpollution>();
            lis = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<airpollution>>() {
            });

            if (lis.size() > 0) {
                result = "[";
                result += "[";
                for (airpollution a : lis) {

                    Date date = a.getObservtime();
                    String fmobt = new SimpleDateFormat("yyyy-MM-dd ").format(date);

                    result += "\"" + fmobt + "\",";
                }
                result = result.substring(0, result.length() - 1) + "],[";
                for (airpollution a : lis) {
                    if (pollution.equals("PM2.5")) {
                        result += "\"" + a.getConcenpm2p5() + "\",";
                    } else if (pollution.equals("PM10")) {
                        result += "\"" + a.getConcenpm10() + "\",";
                    } else if (pollution.equals("AQI")) {
                        result += "\"" + a.getAqi() + "\",";
                    } else if (pollution.equals("SO2")) {
                        result += "\"" + a.getConcenso2() + "\",";
                    } else if (pollution.equals("CO2")) {
                        result += "\"" + a.getConcenno2() + "\",";
                    } else if (pollution.equals("CO")) {
                        result += "\"" + a.getConcenco() + "\",";
                    } else if (pollution.equals("O3")) {
                        result += "\"" + a.getConceno3() + "\",";
                    }
                }

                result = result.substring(0, result.length() - 1) + "]]";
            } else {
                result = "[]";
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "[{\"returnState\":\"0\"}]";
        }
        return result;
    }
}
